use of com.hazelcast.nio.serialization.Portable in project hazelcast by hazelcast.
the class PortableSerializer method createMorphingReader.
DefaultPortableReader createMorphingReader(BufferObjectDataInput in) throws IOException {
int factoryId = in.readInt();
int classId = in.readInt();
int version = in.readInt();
Portable portable = createNewPortableInstance(factoryId, classId);
int portableVersion = findPortableVersion(factoryId, classId, portable);
return createReader(in, factoryId, classId, version, portableVersion);
}
use of com.hazelcast.nio.serialization.Portable in project hazelcast by hazelcast.
the class PortableSerializer method readAndInitialize.
Portable readAndInitialize(BufferObjectDataInput in, int factoryId, int classId) throws IOException {
Portable p = read(in, factoryId, classId);
final ManagedContext managedContext = context.getManagedContext();
return managedContext != null ? (Portable) managedContext.initialize(p) : p;
}
use of com.hazelcast.nio.serialization.Portable 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.Portable 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.Portable in project hazelcast by hazelcast.
the class DefaultPortableReaderPerformanceTest method setup.
@Setup
public void setup() throws Exception {
ss = new DefaultSerializationServiceBuilder().addPortableFactory(DefaultPortableReaderQuickTest.TestPortableFactory.ID, new DefaultPortableReaderQuickTest.TestPortableFactory()).build();
Portable primitive = new DefaultPortableReaderTestStructure.PrimitivePortable();
primitiveReader = reader(primitive);
reader = reader(PORSCHE);
}
Aggregations