Search in sources :

Example 1 with FieldDefinition

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

the class MorphingPortableReader method readChar.

@Override
public char readChar(String fieldName) throws IOException {
    FieldDefinition fd = cd.getField(fieldName);
    if (fd == null) {
        return 0;
    }
    validateTypeCompatibility(fd, CHAR);
    return super.readChar(fieldName);
}
Also used : FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition)

Example 2 with FieldDefinition

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

the class MorphingPortableReader method readFloatArray.

@Override
public float[] readFloatArray(String fieldName) throws IOException {
    FieldDefinition fd = cd.getField(fieldName);
    if (fd == null) {
        return null;
    }
    validateTypeCompatibility(fd, FLOAT_ARRAY);
    return super.readFloatArray(fieldName);
}
Also used : FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition)

Example 3 with FieldDefinition

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

the class MorphingPortableReader method readShortArray.

@Override
public short[] readShortArray(String fieldName) throws IOException {
    FieldDefinition fd = cd.getField(fieldName);
    if (fd == null) {
        return null;
    }
    validateTypeCompatibility(fd, SHORT_ARRAY);
    return super.readShortArray(fieldName);
}
Also used : FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition)

Example 4 with FieldDefinition

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

the class DefaultPortableWriter method writePortable.

@Override
public void writePortable(String fieldName, Portable portable) throws IOException {
    FieldDefinition fd = setPosition(fieldName, FieldType.PORTABLE);
    final boolean isNull = portable == null;
    out.writeBoolean(isNull);
    out.writeInt(fd.getFactoryId());
    out.writeInt(fd.getClassId());
    if (!isNull) {
        checkPortableAttributes(fd, portable);
        serializer.writeInternal(out, portable);
    }
}
Also used : FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition)

Example 5 with FieldDefinition

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

the class DefaultPortableWriter method setPosition.

private FieldDefinition setPosition(String fieldName, FieldType fieldType) throws IOException {
    if (raw) {
        throw new HazelcastSerializationException("Cannot write Portable fields after getRawDataOutput() is called!");
    }
    FieldDefinition fd = cd.getField(fieldName);
    if (fd == null) {
        throw new HazelcastSerializationException("Invalid field name: '" + fieldName + "' for ClassDefinition {id: " + cd.getClassId() + ", version: " + cd.getVersion() + "}");
    }
    if (writtenFields.add(fieldName)) {
        int pos = out.position();
        int index = fd.getIndex();
        out.writeInt(offset + index * INT_SIZE_IN_BYTES, pos);
        out.writeShort(fieldName.length());
        out.writeBytes(fieldName);
        out.writeByte(fieldType.getId());
    } else {
        throw new HazelcastSerializationException("Field '" + fieldName + "' has already been written!");
    }
    return fd;
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition)

Aggregations

FieldDefinition (com.hazelcast.nio.serialization.FieldDefinition)32 ParallelTest (com.hazelcast.test.annotation.ParallelTest)11 QuickTest (com.hazelcast.test.annotation.QuickTest)11 Test (org.junit.Test)11 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)5 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)2 PortableContext (com.hazelcast.internal.serialization.PortableContext)1 DefaultPortableReader (com.hazelcast.internal.serialization.impl.DefaultPortableReader)1 Data (com.hazelcast.nio.serialization.Data)1 Portable (com.hazelcast.nio.serialization.Portable)1 PortableReader (com.hazelcast.nio.serialization.PortableReader)1