Search in sources :

Example 1 with ClassDefinition

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;
}
Also used : ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition)

Example 2 with ClassDefinition

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();
}
Also used : ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition)

Example 3 with ClassDefinition

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);
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition)

Example 4 with ClassDefinition

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);
}
Also used : Portable(com.hazelcast.nio.serialization.Portable) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder)

Example 5 with ClassDefinition

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;
}
Also used : ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput)

Aggregations

ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)70 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)37 Test (org.junit.Test)25 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)16 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)15 QuickTest (com.hazelcast.test.annotation.QuickTest)15 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 FieldDefinition (com.hazelcast.nio.serialization.FieldDefinition)7 GenericRecordBuilder (com.hazelcast.nio.serialization.GenericRecordBuilder)7 Parameters (junitparams.Parameters)7 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)6 MappingField (com.hazelcast.sql.impl.schema.MappingField)6 Portable (com.hazelcast.nio.serialization.Portable)5 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 SerializationConfig (com.hazelcast.config.SerializationConfig)3 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)3 Data (com.hazelcast.internal.serialization.Data)3 BufferObjectDataInput (com.hazelcast.nio.BufferObjectDataInput)3