Search in sources :

Example 1 with InnerPortable

use of com.hazelcast.internal.serialization.impl.portable.InnerPortable in project hazelcast by hazelcast.

the class AbstractGenericRecordIntegrationTest method createGenericRecord.

@Nonnull
private GenericRecord createGenericRecord(MainPortable expectedPortable) {
    InnerPortable inner = expectedPortable.p;
    ClassDefinition namedPortableClassDefinition = new ClassDefinitionBuilder(TestSerializationConstants.PORTABLE_FACTORY_ID, TestSerializationConstants.NAMED_PORTABLE).addStringField("name").addIntField("myint").build();
    ClassDefinition innerPortableClassDefinition = new ClassDefinitionBuilder(TestSerializationConstants.PORTABLE_FACTORY_ID, TestSerializationConstants.INNER_PORTABLE).addByteArrayField("b").addCharArrayField("c").addShortArrayField("s").addIntArrayField("i").addLongArrayField("l").addFloatArrayField("f").addDoubleArrayField("d").addPortableArrayField("nn", namedPortableClassDefinition).addDecimalArrayField("bigDecimals").addTimeArrayField("localTimes").addDateArrayField("localDates").addTimestampArrayField("localDateTimes").addTimestampWithTimezoneArrayField("offsetDateTimes").build();
    ClassDefinition mainPortableClassDefinition = new ClassDefinitionBuilder(PortableTest.PORTABLE_FACTORY_ID, TestSerializationConstants.MAIN_PORTABLE).addByteField("b").addBooleanField("bool").addCharField("c").addShortField("s").addIntField("i").addLongField("l").addFloatField("f").addDoubleField("d").addStringField("str").addPortableField("p", innerPortableClassDefinition).addDecimalField("bigDecimal").addTimeField("localTime").addDateField("localDate").addTimestampField("localDateTime").addTimestampWithTimezoneField("offsetDateTime").build();
    GenericRecord[] namedRecords = new GenericRecord[inner.nn.length];
    int i = 0;
    for (NamedPortable namedPortable : inner.nn) {
        GenericRecord namedRecord = GenericRecordBuilder.portable(namedPortableClassDefinition).setString("name", inner.nn[i].name).setInt32("myint", inner.nn[i].myint).build();
        namedRecords[i++] = namedRecord;
    }
    GenericRecord innerRecord = GenericRecordBuilder.portable(innerPortableClassDefinition).setArrayOfInt8("b", inner.bb).setArrayOfChar("c", inner.cc).setArrayOfInt16("s", inner.ss).setArrayOfInt32("i", inner.ii).setArrayOfInt64("l", inner.ll).setArrayOfFloat32("f", inner.ff).setArrayOfFloat64("d", inner.dd).setArrayOfGenericRecord("nn", namedRecords).setArrayOfDecimal("bigDecimals", inner.bigDecimals).setArrayOfTime("localTimes", inner.localTimes).setArrayOfDate("localDates", inner.localDates).setArrayOfTimestamp("localDateTimes", inner.localDateTimes).setArrayOfTimestampWithTimezone("offsetDateTimes", inner.offsetDateTimes).build();
    return GenericRecordBuilder.portable(mainPortableClassDefinition).setInt8("b", expectedPortable.b).setBoolean("bool", expectedPortable.bool).setChar("c", expectedPortable.c).setInt16("s", expectedPortable.s).setInt32("i", expectedPortable.i).setInt64("l", expectedPortable.l).setFloat32("f", expectedPortable.f).setFloat64("d", expectedPortable.d).setString("str", expectedPortable.str).setGenericRecord("p", innerRecord).setDecimal("bigDecimal", expectedPortable.bigDecimal).setTime("localTime", expectedPortable.localTime).setDate("localDate", expectedPortable.localDate).setTimestamp("localDateTime", expectedPortable.localDateTime).setTimestampWithTimezone("offsetDateTime", expectedPortable.offsetDateTime).build();
}
Also used : InnerPortable(com.hazelcast.internal.serialization.impl.portable.InnerPortable) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) GenericRecord(com.hazelcast.nio.serialization.GenericRecord) ClassDefinitionBuilder(com.hazelcast.nio.serialization.ClassDefinitionBuilder) NamedPortable(com.hazelcast.internal.serialization.impl.portable.NamedPortable) Nonnull(javax.annotation.Nonnull)

Example 2 with InnerPortable

use of com.hazelcast.internal.serialization.impl.portable.InnerPortable in project hazelcast by hazelcast.

the class AbstractGenericRecordIntegrationTest method createMainPortable.

@Nonnull
private MainPortable createMainPortable() {
    NamedPortable[] nn = new NamedPortable[2];
    nn[0] = new NamedPortable("name", 123);
    nn[1] = new NamedPortable("name", 123);
    InnerPortable inner = new InnerPortable(new byte[] { 0, 1, 2 }, new char[] { 'c', 'h', 'a', 'r' }, new short[] { 3, 4, 5 }, new int[] { 9, 8, 7, 6 }, new long[] { 0, 1, 5, 7, 9, 11 }, new float[] { 0.6543f, -3.56f, 45.67f }, new double[] { 456.456, 789.789, 321.321 }, nn, new BigDecimal[] { new BigDecimal("12345"), new BigDecimal("123456") }, new LocalTime[] { LocalTime.now(), LocalTime.now() }, new LocalDate[] { LocalDate.now(), LocalDate.now() }, new LocalDateTime[] { LocalDateTime.now() }, new OffsetDateTime[] { OffsetDateTime.now() });
    return new MainPortable((byte) 113, true, 'x', (short) -500, 56789, -50992225L, 900.5678f, -897543.3678909d, "this is main portable object created for testing!", inner, new BigDecimal("12312313"), LocalTime.now(), LocalDate.now(), LocalDateTime.now(), OffsetDateTime.now());
}
Also used : MainPortable(com.hazelcast.internal.serialization.impl.portable.MainPortable) InnerPortable(com.hazelcast.internal.serialization.impl.portable.InnerPortable) BigDecimal(java.math.BigDecimal) NamedPortable(com.hazelcast.internal.serialization.impl.portable.NamedPortable) Nonnull(javax.annotation.Nonnull)

Aggregations

InnerPortable (com.hazelcast.internal.serialization.impl.portable.InnerPortable)2 NamedPortable (com.hazelcast.internal.serialization.impl.portable.NamedPortable)2 Nonnull (javax.annotation.Nonnull)2 MainPortable (com.hazelcast.internal.serialization.impl.portable.MainPortable)1 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)1 ClassDefinitionBuilder (com.hazelcast.nio.serialization.ClassDefinitionBuilder)1 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)1 BigDecimal (java.math.BigDecimal)1