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;
}
use of com.hazelcast.nio.serialization.ClassDefinition in project hazelcast by hazelcast.
the class PortableContextImpl method getFieldDefinition.
@Override
public // TODO cache the result
FieldDefinition getFieldDefinition(ClassDefinition classDef, String name) {
FieldDefinition fd = classDef.getField(name);
if (fd == null) {
if (name.contains(".")) {
String[] fieldNames = NESTED_FIELD_PATTERN.split(name);
if (fieldNames.length <= 1) {
return fd;
}
ClassDefinition currentClassDef = classDef;
for (int i = 0; i < fieldNames.length; i++) {
fd = currentClassDef.getField(fieldNames[i]);
if (fd == null) {
fd = currentClassDef.getField(extractAttributeNameNameWithoutArguments(fieldNames[i]));
}
// This is not enough to fully implement issue: https://github.com/hazelcast/hazelcast/issues/3927
if (i == fieldNames.length - 1) {
break;
}
if (fd == null) {
throw new IllegalArgumentException("Unknown field: " + name);
}
currentClassDef = lookupClassDefinition(fd.getFactoryId(), fd.getClassId(), fd.getVersion());
if (currentClassDef == null) {
throw new IllegalArgumentException("Not a registered Portable field: " + fd);
}
}
} else {
fd = classDef.getField(extractAttributeNameNameWithoutArguments(name));
}
}
return fd;
}
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 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 PortableSerializer method readAsGenericRecord.
<T> T readAsGenericRecord(BufferObjectDataInput in, int factoryId, int classId, boolean readGenericLazy) throws IOException {
if (readGenericLazy) {
int version = in.readInt();
ClassDefinition cd = setupPositionAndDefinition(in, factoryId, classId, version);
PortableInternalGenericRecord reader = new PortableInternalGenericRecord(this, in, cd, true);
return (T) reader;
}
return readPortableGenericRecord(in, factoryId, classId);
}
Aggregations