Search in sources :

Example 16 with BinarySerializer

use of net.morimekta.providence.serializer.BinarySerializer in project providence by morimekta.

the class ProvidenceTest method testAutoIdFields.

@Test
public void testAutoIdFields() throws IOException {
    AutoIdFields af = AutoIdFields.builder().setBooleanValue(false).setByteValue((byte) 4).setShortValue((short) 6).setIntegerValue(8).setLongValue(10L).setDoubleValue(12.12).setStringValue("a string").setBinaryValue(Binary.fromHexString("0123456789abcdef")).setCompactValue(new CompactFields("name", 14, "label")).setEnumValue(Value.SIXTEENTH).build();
    BinarySerializer serializer = new BinarySerializer();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    serializer.serialize(baos, af);
    AutoIdFields af2 = serializer.deserialize(new ByteArrayInputStream(baos.toByteArray()), AutoIdFields.kDescriptor);
    assertThat(af2, is(equalToMessage(af)));
    // An interesting side effect from auto ID fields, is that the numeric
    // order is reverse that of declared order. Always.
    assertEquals("{\n" + "  compactValue = {\n" + "    name = \"name\"\n" + "    id = 14\n" + "    label = \"label\"\n" + "  }\n" + "  enumValue = SIXTEENTH\n" + "  binaryValue = b64(ASNFZ4mrze8)\n" + "  stringValue = \"a string\"\n" + "  doubleValue = 12.12\n" + "  longValue = 10\n" + "  integerValue = 8\n" + "  shortValue = 6\n" + "  byteValue = 4\n" + "  booleanValue = false\n" + "}", debugString(af2));
}
Also used : AutoIdFields(net.morimekta.test.providence.testing.AutoIdFields) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CompactFields(net.morimekta.test.providence.testing.CompactFields) BinarySerializer(net.morimekta.providence.serializer.BinarySerializer) Test(org.junit.Test)

Aggregations

BinarySerializer (net.morimekta.providence.serializer.BinarySerializer)16 Test (org.junit.Test)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 InetSocketAddress (java.net.InetSocketAddress)4 ExecutorService (java.util.concurrent.ExecutorService)4 Iface (net.morimekta.test.thrift.thrift.service.MyService.Iface)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 UncheckedIOException (java.io.UncheckedIOException)3 CompactFields (net.morimekta.test.providence.core.CompactFields)3 Duration (org.awaitility.Duration)3 File (java.io.File)2 ConnectException (java.net.ConnectException)2 Serializer (net.morimekta.providence.serializer.Serializer)2 MessageGenerator (net.morimekta.providence.util_internal.MessageGenerator)2 MyService (net.morimekta.test.providence.thrift.service.MyService)2 BeforeClass (org.junit.BeforeClass)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Path (java.nio.file.Path)1