use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.
the class Schema method init.
private void init() {
List<FieldDescriptor> fixedSizeFields = new ArrayList<>();
List<FieldDescriptor> booleanFields = new ArrayList<>();
List<FieldDescriptor> variableSizeFields = new ArrayList<>();
for (FieldDescriptor descriptor : fieldDefinitionMap.values()) {
FieldKind fieldKind = descriptor.getKind();
if (fieldOperations(fieldKind).kindSizeInBytes() == VARIABLE_SIZE) {
variableSizeFields.add(descriptor);
} else {
if (FieldKind.BOOLEAN == fieldKind) {
booleanFields.add(descriptor);
} else {
fixedSizeFields.add(descriptor);
}
}
}
fixedSizeFields.sort(Comparator.comparingInt(d -> fieldOperations(((FieldDescriptor) d).getKind()).kindSizeInBytes()).reversed());
int offset = 0;
for (FieldDescriptor descriptor : fixedSizeFields) {
descriptor.setOffset(offset);
offset += fieldOperations(descriptor.getKind()).kindSizeInBytes();
}
int bitOffset = 0;
for (FieldDescriptor descriptor : booleanFields) {
descriptor.setOffset(offset);
descriptor.setBitOffset((byte) (bitOffset % Byte.SIZE));
bitOffset++;
if (bitOffset % Byte.SIZE == 0) {
offset += 1;
}
}
if (bitOffset % Byte.SIZE != 0) {
offset++;
}
fixedSizeFieldsLength = offset;
int index = 0;
for (FieldDescriptor descriptor : variableSizeFields) {
descriptor.setIndex(index++);
}
numberVarSizeFields = index;
schemaId = RabinFingerprint.fingerprint64(this);
}
use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.
the class SerializingGenericRecordCloner method build.
@Override
@Nonnull
public GenericRecord build() {
try {
for (FieldDescriptor field : schema.getFields()) {
String fieldName = field.getFieldName();
Writer writer = fields.get(fieldName);
if (writer != null) {
writer.write();
} else {
// Field is not overwritten. Write the field from the generic record.
FieldKind fieldKind = field.getKind();
fieldOperations(fieldKind).writeFieldFromRecordToWriter(cw, genericRecord, fieldName);
}
}
cw.end();
byte[] bytes = cw.toByteArray();
Class associatedClass = genericRecord.getAssociatedClass();
BufferObjectDataInput dataInput = bufferObjectDataInputFunc.apply(bytes);
return new DefaultCompactReader(serializer, dataInput, schema, associatedClass, false);
} catch (IOException e) {
throw new HazelcastSerializationException(e);
}
}
use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.
the class DeserializedGenericRecord method getArrayOfInt32.
@Override
@Nullable
public int[] getArrayOfInt32(@Nonnull String fieldName) {
FieldKind fieldKind = check(fieldName, ARRAY_OF_INT32, ARRAY_OF_NULLABLE_INT32);
if (fieldKind == ARRAY_OF_NULLABLE_INT32) {
Integer[] array = (Integer[]) objects.get(fieldName);
int[] result = new int[array.length];
for (int i = 0; i < array.length; i++) {
if (array[i] == null) {
throw exceptionForUnexpectedNullValueInArray(fieldName, "Int32");
}
result[i] = array[i];
}
return result;
}
return (int[]) objects.get(fieldName);
}
use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.
the class DeserializedGenericRecord method getArrayOfFloat64.
@Override
@Nullable
public double[] getArrayOfFloat64(@Nonnull String fieldName) {
FieldKind fieldKind = check(fieldName, ARRAY_OF_FLOAT64, ARRAY_OF_NULLABLE_FLOAT64);
if (fieldKind == ARRAY_OF_NULLABLE_FLOAT64) {
Double[] array = (Double[]) objects.get(fieldName);
double[] result = new double[array.length];
for (int i = 0; i < array.length; i++) {
if (array[i] == null) {
throw exceptionForUnexpectedNullValueInArray(fieldName, "Float64");
}
result[i] = array[i];
}
return result;
}
return (double[]) objects.get(fieldName);
}
use of com.hazelcast.nio.serialization.FieldKind in project hazelcast by hazelcast.
the class DeserializedGenericRecord method getArrayOfNullableInt32.
@Nullable
@Override
public Integer[] getArrayOfNullableInt32(@Nonnull String fieldName) {
FieldKind fieldKind = check(fieldName, ARRAY_OF_INT32, ARRAY_OF_NULLABLE_INT32);
if (fieldKind == ARRAY_OF_INT32) {
int[] array = (int[]) objects.get(fieldName);
Integer[] result = new Integer[array.length];
Arrays.setAll(result, i -> array[i]);
return result;
}
return (Integer[]) objects.get(fieldName);
}
Aggregations