use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class PortableSerializer method writeInternal.
void writeInternal(BufferObjectDataOutput out, Portable p) throws IOException {
ClassDefinition cd = context.lookupOrRegisterClassDefinition(p);
out.writeInt(cd.getVersion());
DefaultPortableWriter writer = new DefaultPortableWriter(this, out, cd);
p.writePortable(writer);
writer.end();
}
use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class ClassDefinitionWriter method writePortable.
@Override
public void writePortable(@Nonnull String fieldName, @Nullable 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.ClassDefinition in project hazelcast by hazelcast.
the class ClassDefinitionWriter method writePortableArray.
@Override
public void writePortableArray(@Nonnull 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.ClassDefinition in project hazelcast by hazelcast.
the class SerializationServiceV1 method registerClassDefinitions.
public void registerClassDefinitions(Collection<ClassDefinition> classDefinitions) {
Map<Integer, Map<Integer, ClassDefinition>> factoryMap = createHashMap(classDefinitions.size());
for (ClassDefinition cd : classDefinitions) {
int factoryId = cd.getFactoryId();
Map<Integer, ClassDefinition> classDefMap = factoryMap.computeIfAbsent(factoryId, k -> new HashMap<>());
int classId = cd.getClassId();
if (classDefMap.containsKey(classId)) {
throw new HazelcastSerializationException("Duplicate registration found for factory-id : " + factoryId + ", class-id " + classId);
}
classDefMap.put(classId, cd);
}
for (ClassDefinition classDefinition : classDefinitions) {
registerClassDefinition(classDefinition, factoryMap);
}
}
use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class SqlClientPortableQueryTest method setup.
@Before
public void setup() {
MapConfig mapConfig = new MapConfig("default").setInMemoryFormat(inMemoryFormat);
Config config = smallInstanceConfig().addMapConfig(mapConfig);
if (clusterHasPortableConfig) {
config.getSerializationConfig().addPortableFactory(PORTABLE_FACTORY_ID, new TestPortableFactory());
}
ClassDefinition childClassDefinition = new ClassDefinitionBuilder(PORTABLE_FACTORY_ID, PORTABLE_CHILD_CLASS_ID, 0).addIntField("i").addIntArrayField("ia").build();
ClassDefinition parentClassDefinition = new ClassDefinitionBuilder(PORTABLE_FACTORY_ID, PORTABLE_PARENT_CLASS_ID, 0).addPortableField("child", childClassDefinition).addIntField("id").build();
config.getSerializationConfig().addClassDefinition(childClassDefinition);
config.getSerializationConfig().addClassDefinition(parentClassDefinition);
factory.newHazelcastInstance(config);
}
Aggregations