Search in sources :

Example 26 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class CompactInternalGenericRecord method getFloat32.

@Override
public float getFloat32(@Nonnull String fieldName) {
    FieldDescriptor fd = getFieldDefinition(fieldName);
    FieldKind fieldKind = fd.getKind();
    switch(fieldKind) {
        case FLOAT32:
            try {
                return in.readFloat(readFixedSizePosition(fd));
            } catch (IOException e) {
                throw illegalStateException(e);
            }
        case NULLABLE_FLOAT32:
            return getVariableSizeAsNonNull(fd, ObjectDataInput::readFloat, "Float32");
        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 27 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class CompactInternalGenericRecord method getNullableInt32.

@Nullable
@Override
public Integer getNullableInt32(@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 getVariableSize(fd, ObjectDataInput::readInt);
        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) Nullable(javax.annotation.Nullable)

Example 28 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class CompactInternalGenericRecord method getArrayOfNullableBoolean.

@Nullable
@Override
public Boolean[] getArrayOfNullableBoolean(@Nonnull String fieldName) {
    FieldDescriptor fd = getFieldDefinition(fieldName);
    FieldKind fieldKind = fd.getKind();
    switch(fieldKind) {
        case ARRAY_OF_BOOLEAN:
            return getVariableSize(fieldName, ARRAY_OF_BOOLEAN, CompactInternalGenericRecord::readBooleanBitsAsNullables);
        case ARRAY_OF_NULLABLE_BOOLEAN:
            return getArrayOfVariableSize(fieldName, ARRAY_OF_NULLABLE_BOOLEAN, Boolean[]::new, ObjectDataInput::readBoolean);
        default:
            throw unexpectedFieldKind(fieldKind, fieldName);
    }
}
Also used : FieldKind(com.hazelcast.nio.serialization.FieldKind) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) Nullable(javax.annotation.Nullable)

Example 29 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class CachePartitionLostListenerTest method test_cachePartitionEventData_deserialization.

@Test
public void test_cachePartitionEventData_deserialization() throws IOException {
    CachePartitionEventData cachePartitionEventData = new CachePartitionEventData("", 0, null);
    ObjectDataInput input = mock(ObjectDataInput.class, withSettings().extraInterfaces(DataReader.class));
    when(input.readString()).thenReturn("cacheName");
    when(input.readInt()).thenReturn(1);
    cachePartitionEventData.readData(input);
    assertEquals("cacheName", cachePartitionEventData.getName());
    assertEquals(1, cachePartitionEventData.getPartitionId());
}
Also used : DataReader(com.hazelcast.internal.nio.DataReader) CachePartitionEventData(com.hazelcast.cache.impl.CachePartitionEventData) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) AbstractPartitionLostListenerTest(com.hazelcast.partition.AbstractPartitionLostListenerTest) Test(org.junit.Test)

Example 30 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class AbstractDataStreamIntegrationTest method testLong.

@Test
public void testLong() throws IOException {
    out.writeLong(Long.MIN_VALUE);
    out.writeLong(-1);
    out.writeLong(Long.MAX_VALUE);
    ObjectDataInput in = getDataInputFromOutput();
    assertEquals(Long.MIN_VALUE, in.readLong());
    assertEquals(-1, in.readLong());
    assertEquals(Long.MAX_VALUE, in.readLong());
}
Also used : ObjectDataInput(com.hazelcast.nio.ObjectDataInput) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ObjectDataInput (com.hazelcast.nio.ObjectDataInput)80 Test (org.junit.Test)35 QuickTest (com.hazelcast.test.annotation.QuickTest)32 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)24 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)17 FieldKind (com.hazelcast.nio.serialization.FieldKind)16 IOException (java.io.IOException)13 ObjectDataOutput (com.hazelcast.nio.ObjectDataOutput)12 Nullable (javax.annotation.Nullable)9 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)7 SerializationConfig (com.hazelcast.config.SerializationConfig)6 StreamSerializer (com.hazelcast.nio.serialization.StreamSerializer)6 Data (com.hazelcast.nio.serialization.Data)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Data (com.hazelcast.internal.serialization.Data)3 SerializationService (com.hazelcast.internal.serialization.SerializationService)3 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)3 HeapData (com.hazelcast.internal.serialization.impl.HeapData)3 SerializationService (com.hazelcast.spi.serialization.SerializationService)3 SerializerConfig (com.hazelcast.config.SerializerConfig)2