use of com.hazelcast.nio.serialization.ClassDefinitionBuilder in project hazelcast by hazelcast.
the class ClassDefinitionWriter method writePortableArray.
@Override
public void writePortableArray(String fieldName, Portable[] portables) throws IOException {
if (portables == null || portables.length == 0) {
throw new HazelcastSerializationException("Cannot write null portable array without explicitly " + "registering class definition!");
}
Portable p = portables[0];
int classId = p.getClassId();
for (int i = 1; i < portables.length; i++) {
if (portables[i].getClassId() != classId) {
throw new IllegalArgumentException("Detected different class-ids in portable array!");
}
}
int version = SerializationUtil.getPortableVersion(p, context.getVersion());
ClassDefinition nestedClassDef = createNestedClassDef(p, new ClassDefinitionBuilder(p.getFactoryId(), classId, version));
builder.addPortableArrayField(fieldName, nestedClassDef);
}
use of com.hazelcast.nio.serialization.ClassDefinitionBuilder in project hazelcast by hazelcast.
the class ClassAndFieldDefinitionTest method testClassDef_equal_hashCode.
@Test
public void testClassDef_equal_hashCode() throws Exception {
ClassDefinitionImpl cdEmpty1 = (ClassDefinitionImpl) new ClassDefinitionBuilder(1, 2, 3).build();
ClassDefinitionImpl cdEmpty2 = (ClassDefinitionImpl) new ClassDefinitionBuilder(1, 2, 3).build();
ClassDefinitionImpl cd1 = (ClassDefinitionImpl) new ClassDefinitionBuilder(1, 2, 5).build();
ClassDefinitionImpl cd2 = (ClassDefinitionImpl) new ClassDefinitionBuilder(2, 2, 3).build();
ClassDefinitionImpl cd3 = (ClassDefinitionImpl) new ClassDefinitionBuilder(1, 9, 3).build();
ClassDefinitionImpl cdWithField = (ClassDefinitionImpl) new ClassDefinitionBuilder(1, 2, 3).addIntField("f1").build();
assertEquals(cdEmpty1, cdEmpty2);
assertNotEquals(cd1, cdEmpty1);
assertNotEquals(cd2, cdEmpty1);
assertNotEquals(cd3, cdEmpty1);
assertNotEquals(cdWithField, classDefinition);
assertNotEquals(cdEmpty1, classDefinition);
assertNotEquals(classDefinition, null);
assertNotEquals(classDefinition, "Another Class");
assertNotEquals(0, cd1.hashCode());
}
use of com.hazelcast.nio.serialization.ClassDefinitionBuilder in project hazelcast by hazelcast.
the class ClassAndFieldDefinitionTest method setUp.
@Before
public void setUp() throws Exception {
ClassDefinitionBuilder builder = new ClassDefinitionBuilder(1, 2, 3);
for (String fieldName : fieldNames) {
builder.addByteField(fieldName);
}
classDefinition = (ClassDefinitionImpl) builder.build();
}
use of com.hazelcast.nio.serialization.ClassDefinitionBuilder in project hazelcast by hazelcast.
the class AbstractNearCacheSerializationCountTest method prepareSerializationConfig.
/**
* Adds the serialization configuration for the used {@link Portable} domain object to the given {@link SerializationConfig}.
*
* @param serializationConfig the given {@link SerializationConfig} for the {@link DataStructureAdapter}
*/
protected static void prepareSerializationConfig(SerializationConfig serializationConfig) {
ClassDefinition classDefinition = new ClassDefinitionBuilder(SerializationCountingData.FACTORY_ID, SerializationCountingData.CLASS_ID).build();
serializationConfig.addClassDefinition(classDefinition);
serializationConfig.addPortableFactory(SerializationCountingData.FACTORY_ID, new PortableFactory() {
@Override
public Portable create(int classId) {
return new SerializationCountingData();
}
});
}
use of com.hazelcast.nio.serialization.ClassDefinitionBuilder in project hazelcast by hazelcast.
the class BinaryCompatibilityTest method createSerializationService.
private SerializationService createSerializationService() {
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.setAllowUnsafe(allowUnsafe);
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