Search in sources :

Example 36 with FieldKind

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

the class CompactInternalGenericRecord method getBoolean.

@Override
public boolean getBoolean(@Nonnull String fieldName) {
    FieldDescriptor fd = getFieldDefinition(fieldName);
    FieldKind fieldKind = fd.getKind();
    switch(fieldKind) {
        case BOOLEAN:
            return getBoolean(fd);
        case NULLABLE_BOOLEAN:
            return getVariableSizeAsNonNull(fd, ObjectDataInput::readBoolean, "Boolean");
        default:
            throw unexpectedFieldKind(BOOLEAN, fieldName);
    }
}
Also used : FieldKind(com.hazelcast.nio.serialization.FieldKind) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Example 37 with FieldKind

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

the class CompactInternalGenericRecord method getInt32.

@Override
public int getInt32(@Nonnull String fieldName) {
    FieldDescriptor fd = getFieldDefinition(fieldName);
    FieldKind fieldKind = fd.getKind();
    switch(fieldKind) {
        case INT32:
            try {
                return in.readInt(readFixedSizePosition(fd));
            } catch (IOException e) {
                throw illegalStateException(e);
            }
        case NULLABLE_INT32:
            return getVariableSizeAsNonNull(fd, ObjectDataInput::readInt, "Int32");
        default:
            throw unexpectedFieldKind(fieldKind, fieldName);
    }
}
Also used : FieldKind(com.hazelcast.nio.serialization.FieldKind) IOException(java.io.IOException) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Example 38 with FieldKind

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

the class CompactInternalGenericRecord method getInt8.

@Override
public byte getInt8(@Nonnull String fieldName) {
    FieldDescriptor fd = getFieldDefinition(fieldName);
    FieldKind fieldKind = fd.getKind();
    switch(fieldKind) {
        case INT8:
            try {
                return in.readByte(readFixedSizePosition(fd));
            } catch (IOException e) {
                throw illegalStateException(e);
            }
        case NULLABLE_INT8:
            return getVariableSizeAsNonNull(fd, ObjectDataInput::readByte, "Int8");
        default:
            throw unexpectedFieldKind(fieldKind, fieldName);
    }
}
Also used : FieldKind(com.hazelcast.nio.serialization.FieldKind) IOException(java.io.IOException) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Example 39 with FieldKind

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

the class CompactInternalGenericRecord method getFixedSizeFieldFromArray.

private <T> T getFixedSizeFieldFromArray(@Nonnull String fieldName, FieldKind fieldKind, Reader<T> reader, int index) {
    checkNotNegative(index, "Array indexes can not be negative");
    int position = readVariableSizeFieldPosition(fieldName, fieldKind);
    if (position == NULL_OFFSET) {
        return null;
    }
    if (readLength(position) <= index) {
        return null;
    }
    int currentPos = in.position();
    try {
        FieldKind singleKind = FieldOperations.getSingleKind(fieldKind);
        int kindSize = FieldOperations.fieldOperations(singleKind).kindSizeInBytes();
        in.position(INT_SIZE_IN_BYTES + position + index * kindSize);
        return reader.read(in);
    } catch (IOException e) {
        throw illegalStateException(e);
    } finally {
        in.position(currentPos);
    }
}
Also used : FieldKind(com.hazelcast.nio.serialization.FieldKind) IOException(java.io.IOException)

Example 40 with FieldKind

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

the class Schema method readData.

@Override
public void readData(ObjectDataInput in) throws IOException {
    typeName = in.readString();
    int fieldDefinitionsSize = in.readInt();
    fieldDefinitionMap = new TreeMap<>(Comparator.naturalOrder());
    for (int i = 0; i < fieldDefinitionsSize; i++) {
        String name = in.readString();
        FieldKind kind = FieldKind.get(in.readInt());
        FieldDescriptor descriptor = new FieldDescriptor(name, kind);
        fieldDefinitionMap.put(name, descriptor);
    }
    init();
}
Also used : FieldKind(com.hazelcast.nio.serialization.FieldKind)

Aggregations

FieldKind (com.hazelcast.nio.serialization.FieldKind)40 Nullable (javax.annotation.Nullable)24 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)17 ObjectDataInput (com.hazelcast.nio.ObjectDataInput)16 IOException (java.io.IOException)14 Nonnull (javax.annotation.Nonnull)3 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)2 QueryDataType (com.hazelcast.sql.impl.type.QueryDataType)2 DeserializedSchemaBoundGenericRecordBuilder (com.hazelcast.internal.serialization.impl.compact.DeserializedSchemaBoundGenericRecordBuilder)1 Schema (com.hazelcast.internal.serialization.impl.compact.Schema)1 FieldTypeToFieldKind (com.hazelcast.internal.serialization.impl.portable.FieldTypeToFieldKind)1 FAILING_TOP_LEVEL_INJECTOR (com.hazelcast.jet.sql.impl.inject.UpsertInjector.FAILING_TOP_LEVEL_INJECTOR)1 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)1 GenericRecordBuilder (com.hazelcast.nio.serialization.GenericRecordBuilder)1 QueryException (com.hazelcast.sql.impl.QueryException)1 BigDecimal (java.math.BigDecimal)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1 OffsetDateTime (java.time.OffsetDateTime)1