use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class PortableSerializer method setupPositionAndDefinition.
public ClassDefinition setupPositionAndDefinition(BufferObjectDataInput in, int factoryId, int classId, int version) throws IOException {
int effectiveVersion = version;
if (effectiveVersion < 0) {
effectiveVersion = context.getVersion();
}
ClassDefinition cd = context.lookupClassDefinition(factoryId, classId, effectiveVersion);
if (cd == null) {
int begin = in.position();
cd = context.readClassDefinition(in, factoryId, classId, effectiveVersion);
in.position(begin);
}
return cd;
}
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 writeNullPortable.
@Override
public void writeNullPortable(String fieldName, int factoryId, int classId) throws IOException {
final ClassDefinition nestedClassDef = context.lookupClassDefinition(factoryId, classId, context.getVersion());
if (nestedClassDef == null) {
throw new HazelcastSerializationException("Cannot write null portable without explicitly " + "registering class definition!");
}
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(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 PortableContextImpl method lookupClassDefinition.
@Override
public ClassDefinition lookupClassDefinition(Data data) throws IOException {
if (!data.isPortable()) {
throw new IllegalArgumentException("Data is not Portable!");
}
BufferObjectDataInput in = serializationService.createObjectDataInput(data);
int factoryId = in.readInt();
int classId = in.readInt();
int version = in.readInt();
ClassDefinition classDefinition = lookupClassDefinition(factoryId, classId, version);
if (classDefinition == null) {
classDefinition = readClassDefinition(in, factoryId, classId, version);
}
return classDefinition;
}
Aggregations