use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.
the class DeserializedGenericRecord method getArrayOfNullableInt64.
@Nullable
@Override
public Long[] getArrayOfNullableInt64(@Nonnull String fieldName) {
FieldKind fieldKind = check(fieldName, ARRAY_OF_INT64, ARRAY_OF_NULLABLE_INT64);
if (fieldKind == ARRAY_OF_INT64) {
long[] array = (long[]) objects.get(fieldName);
Long[] result = new Long[array.length];
Arrays.setAll(result, i -> array[i]);
return result;
}
return (Long[]) objects.get(fieldName);
}
use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.
the class DeserializedGenericRecord method check.
private FieldKind check(@Nonnull String fieldName, @Nonnull FieldKind... kinds) {
FieldDescriptor fd = schema.getField(fieldName);
if (fd == null) {
throw new HazelcastSerializationException("Invalid field name: '" + fieldName + " for " + schema);
}
boolean valid = false;
FieldKind fieldKind = fd.getKind();
for (FieldKind kind : kinds) {
valid |= fieldKind == kind;
}
if (!valid) {
throw new HazelcastSerializationException("Invalid field kind: '" + fieldName + " for " + schema + ", valid field kinds : " + Arrays.toString(kinds) + ", found : " + fieldKind);
}
return fieldKind;
}
use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.
the class CompactInternalGenericRecord method getNullableInt16.
@Nullable
@Override
public Short getNullableInt16(@Nonnull String fieldName) {
FieldDescriptor fd = getFieldDefinition(fieldName);
FieldKind fieldKind = fd.getKind();
switch(fieldKind) {
case INT16:
try {
return in.readShort(readFixedSizePosition(fd));
} catch (IOException e) {
throw illegalStateException(e);
}
case NULLABLE_INT16:
return getVariableSize(fd, ObjectDataInput::readShort);
default:
throw unexpectedFieldKind(fieldKind, fieldName);
}
}
use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.
the class CompactInternalGenericRecord method getInt64.
@Override
public long getInt64(@Nonnull String fieldName) {
FieldDescriptor fd = getFieldDefinition(fieldName);
FieldKind fieldKind = fd.getKind();
switch(fieldKind) {
case INT64:
try {
return in.readLong(readFixedSizePosition(fd));
} catch (IOException e) {
throw illegalStateException(e);
}
case NULLABLE_INT64:
return getVariableSizeAsNonNull(fd, ObjectDataInput::readLong, "Int64");
default:
throw unexpectedFieldKind(fieldKind, fieldName);
}
}
use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.
the class CompactInternalGenericRecord method getArrayOfNullable.
private <T> T[] getArrayOfNullable(@Nonnull String fieldName, Reader<T> reader, Function<Integer, T[]> constructor, FieldKind primitiveKind, FieldKind nullableKind) {
FieldDescriptor fd = getFieldDefinition(fieldName);
FieldKind fieldKind = fd.getKind();
if (fieldKind == primitiveKind) {
return getPrimitiveArrayAsNullableArray(fd, constructor, reader);
} else if (fieldKind == nullableKind) {
return getArrayOfVariableSize(fd, constructor, reader);
}
throw unexpectedFieldKind(fieldKind, fieldName);
}
Aggregations