Search in sources :

Example 1 with FieldType

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

Example 2 with FieldType

use of com.hazelcast.nio.serialization.FieldType in project hazelcast by hazelcast.

the class ClassAndFieldDefinitionTest method testClassDef_getFieldType.

@Test
public void testClassDef_getFieldType() throws Exception {
    for (String fieldName : fieldNames) {
        FieldType fieldType = classDefinition.getFieldType(fieldName);
        assertNotNull(fieldType);
    }
}
Also used : FieldType(com.hazelcast.nio.serialization.FieldType) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

FieldType (com.hazelcast.nio.serialization.FieldType)2 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)1 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1