use of com.hazelcast.nio.serialization.ClassDefinitionBuilder in project hazelcast by hazelcast.
the class ClassDefinitionWriter method writePortable.
@Override
public void writePortable(String fieldName, Portable portable) throws IOException {
if (portable == null) {
throw new HazelcastSerializationException("Cannot write null portable without explicitly " + "registering class definition!");
}
int version = SerializationUtil.getPortableVersion(portable, context.getVersion());
ClassDefinition nestedClassDef = createNestedClassDef(portable, new ClassDefinitionBuilder(portable.getFactoryId(), portable.getClassId(), version));
builder.addPortableField(fieldName, nestedClassDef);
}
use of com.hazelcast.nio.serialization.ClassDefinitionBuilder in project hazelcast by hazelcast.
the class PortableContextImpl method readClassDefinition.
ClassDefinition readClassDefinition(BufferObjectDataInput in, int factoryId, int classId, int version) throws IOException {
boolean register = true;
ClassDefinitionBuilder builder = new ClassDefinitionBuilder(factoryId, classId, version);
// final position after portable is read
in.readInt();
// field count
int fieldCount = in.readInt();
int offset = in.position();
for (int i = 0; i < fieldCount; i++) {
int pos = in.readInt(offset + i * Bits.INT_SIZE_IN_BYTES);
in.position(pos);
short len = in.readShort();
char[] chars = new char[len];
for (int k = 0; k < len; k++) {
chars[k] = (char) in.readUnsignedByte();
}
FieldType type = FieldType.get(in.readByte());
String name = new String(chars);
int fieldFactoryId = 0;
int fieldClassId = 0;
int fieldVersion = 0;
if (type == FieldType.PORTABLE) {
// is null
if (in.readBoolean()) {
register = false;
}
fieldFactoryId = in.readInt();
fieldClassId = in.readInt();
// TODO: what there's a null inner Portable field
if (register) {
fieldVersion = in.readInt();
readClassDefinition(in, fieldFactoryId, fieldClassId, fieldVersion);
}
} else if (type == FieldType.PORTABLE_ARRAY) {
int k = in.readInt();
fieldFactoryId = in.readInt();
fieldClassId = in.readInt();
// TODO: what there's a null inner Portable field
if (k > 0) {
int p = in.readInt();
in.position(p);
fieldVersion = in.readInt();
readClassDefinition(in, fieldFactoryId, fieldClassId, fieldVersion);
} else {
register = false;
}
}
builder.addField(new FieldDefinitionImpl(i, name, type, fieldFactoryId, fieldClassId, fieldVersion));
}
ClassDefinition classDefinition = builder.build();
if (register) {
classDefinition = registerClassDefinition(classDefinition);
}
return classDefinition;
}
use of com.hazelcast.nio.serialization.ClassDefinitionBuilder in project hazelcast by hazelcast.
the class BinaryCompatibilityFileGenerator method createSerializationService.
private static SerializationService createSerializationService(ByteOrder byteOrder) {
SerializationConfig config = new SerializationConfig();
{
SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setImplementation(new CustomByteArraySerializer()).setTypeClass(CustomByteArraySerializable.class);
config.addSerializerConfig(serializerConfig);
}
{
SerializerConfig serializerConfig = new SerializerConfig();
serializerConfig.setImplementation(new CustomStreamSerializer()).setTypeClass(CustomStreamSerializable.class);
config.addSerializerConfig(serializerConfig);
}
config.setByteOrder(byteOrder);
ClassDefinition classDefinition = new ClassDefinitionBuilder(ReferenceObjects.PORTABLE_FACTORY_ID, ReferenceObjects.INNER_PORTABLE_CLASS_ID).addIntField("i").addFloatField("f").build();
return new DefaultSerializationServiceBuilder().setConfig(config).setVersion(VERSION).addPortableFactory(ReferenceObjects.PORTABLE_FACTORY_ID, new APortableFactory()).addDataSerializableFactory(ReferenceObjects.IDENTIFIED_DATA_SERIALIZABLE_FACTORY_ID, new ADataSerializableFactory()).addClassDefinition(classDefinition).build();
}
Aggregations