use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class PortableSerializer method createReader.
public DefaultPortableReader createReader(BufferObjectDataInput in, int factoryId, int classId, int version, int portableVersion) throws IOException {
ClassDefinition cd = setupPositionAndDefinition(in, factoryId, classId, version);
DefaultPortableReader reader;
if (portableVersion == cd.getVersion()) {
reader = new DefaultPortableReader(this, in, cd);
} else {
reader = new MorphingPortableReader(this, in, cd);
}
return reader;
}
use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class SerializationServiceV1 method registerClassDefinition.
protected void registerClassDefinition(ClassDefinition cd, Map<Integer, ClassDefinition> classDefMap, boolean checkClassDefErrors) {
final Set<String> fieldNames = cd.getFieldNames();
for (String fieldName : fieldNames) {
FieldDefinition fd = cd.getField(fieldName);
if (fd.getType() == FieldType.PORTABLE || fd.getType() == FieldType.PORTABLE_ARRAY) {
int classId = fd.getClassId();
ClassDefinition nestedCd = classDefMap.get(classId);
if (nestedCd != null) {
registerClassDefinition(nestedCd, classDefMap, checkClassDefErrors);
portableContext.registerClassDefinition(nestedCd);
} else if (checkClassDefErrors) {
throw new HazelcastSerializationException("Could not find registered ClassDefinition for class-id: " + classId);
}
}
}
portableContext.registerClassDefinition(cd);
}
use of com.hazelcast.nio.serialization.ClassDefinition 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.ClassDefinition 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.ClassDefinition in project hazelcast by hazelcast.
the class PortableContextImpl method lookupOrRegisterClassDefinition.
@Override
public ClassDefinition lookupOrRegisterClassDefinition(Portable p) throws IOException {
int portableVersion = SerializationUtil.getPortableVersion(p, version);
ClassDefinition cd = lookupClassDefinition(p.getFactoryId(), p.getClassId(), portableVersion);
if (cd == null) {
ClassDefinitionWriter writer = new ClassDefinitionWriter(this, p.getFactoryId(), p.getClassId(), portableVersion);
p.writePortable(writer);
cd = writer.registerAndGet();
}
return cd;
}
Aggregations