public void testFoo() throws Exception { Foo foo = SerializableObjects.foo; protobufRoundTrip(foo, Foo.getSchema(), Foo.getPipeSchema(), false); protostuffRoundTrip(foo, Foo.getSchema(), Foo.getPipeSchema(), false); // numeric protobufRoundTrip(foo, Foo.getSchema(), Foo.getPipeSchema(), true); protostuffRoundTrip(foo, Foo.getSchema(), Foo.getPipeSchema(), true); }
public void testFoo() throws Exception { Foo foo = SerializableObjects.foo; roundTrip(foo, Foo.getSchema(), Foo.getPipeSchema()); }
public void testFoo() throws Exception { Schema<Foo> schema = Foo.getSchema(); Foo message = foo; byte[] data = XmlXIOUtil.toByteArray(message, schema, buf()); ByteArrayOutputStream out = new ByteArrayOutputStream(); XmlXIOUtil.writeTo(out, message, schema, buf()); assertTrue(Arrays.equals(data, out.toByteArray())); }
public void testReference() throws Exception { Foo fooCompare = newFoo(); // verify checkReference(fooCompare); byte[] data = toByteArray(fooCompare, Foo.getSchema()); // from byte array Foo fooFromByteArray = new Foo(); mergeFrom(data, 0, data.length, fooFromByteArray, Foo.getSchema()); SerializableObjects.assertEquals(fooCompare, fooFromByteArray); // verify parsed message checkReference(fooFromByteArray); // from inputstream Foo fooFromStream = new Foo(); ByteArrayInputStream in = new ByteArrayInputStream(data); mergeFrom(in, fooFromStream, Foo.getSchema()); SerializableObjects.assertEquals(fooCompare, fooFromStream); // verify parsed message checkReference(fooFromStream); }
public void testFoo() throws Exception { Schema<Foo> schema = Foo.getSchema(); Foo message = SerializableObjects.foo; ByteArrayOutputStream out = new ByteArrayOutputStream(); int size = optWriteDelimitedTo(out, message, schema, buf()); int delimSize = ProtobufOutput.computeRawVarint32Size(size); byte[] data = out.toByteArray(); int expectedSize = size + delimSize; assertEquals(expectedSize, data.length); verifyOptData(data, message, schema, buf()); ByteArrayInputStream in = new ByteArrayInputStream(data); Foo parsedMessage = schema.newMessage(); boolean merged = optMergeDelimitedFrom(in, parsedMessage, schema, buf(512)); assertTrue(merged); assertEquals(message, parsedMessage); }
public void testFooEmpty() throws Exception { Schema<Foo> schema = Foo.getSchema(); Foo message = new Foo(); ByteArrayOutputStream out = new ByteArrayOutputStream(); int size = optWriteDelimitedTo(out, message, schema, buf()); int delimSize = ProtobufOutput.computeRawVarint32Size(size); byte[] data = out.toByteArray(); int expectedSize = size + delimSize; assertEquals(expectedSize, data.length); verifyOptData(data, message, schema, buf()); // empty assertEquals(size, 0); assertEquals(delimSize, 1); ByteArrayInputStream in = new ByteArrayInputStream(data); Foo parsedMessage = schema.newMessage(); boolean merged = optMergeDelimitedFrom(in, parsedMessage, schema, buf()); assertTrue(merged); assertEquals(message, parsedMessage); }
public void testFooTooLarge() throws Exception { Schema<Foo> schema = Foo.getSchema(); Foo message = SerializableObjects.newFoo( new Integer[] { 90210, -90210, 0, 128 }, new String[] { "ab", "cd" }, new Bar[] { SerializableObjects.bar, SerializableObjects.negativeBar }, new EnumSample[] { EnumSample.TYPE0, EnumSample.TYPE2 }, new ByteString[] { ByteString.copyFromUtf8("ef"), ByteString.copyFromUtf8("gh") }, new Boolean[] { true, false }, new Float[] { 1234.4321f, -1234.4321f, 0f }, new Double[] { 12345678.87654321d, -12345678.87654321d, 0d }, new Long[] { 7060504030201l, -7060504030201l, 0l }); ByteArrayOutputStream out = new ByteArrayOutputStream(); int size = optWriteDelimitedTo(out, message, schema, buf()); int delimSize = ProtobufOutput.computeRawVarint32Size(size); byte[] data = out.toByteArray(); int expectedSize = size + delimSize; // 258 assertEquals(expectedSize, data.length); verifyOptData(data, message, schema, buf()); ByteArrayInputStream in = new ByteArrayInputStream(data); Foo parsedMessage = schema.newMessage(); boolean merged = optMergeDelimitedFrom(in, parsedMessage, schema, buf(256)); assertFalse(merged); }
static void compareFoo() { io.protostuff.Foo foo1 = io.protostuff.SerializableObjects.foo; Schema<io.protostuff.Foo> schema1 = io.protostuff.Foo .getSchema(); Foo foo2 = SerializableObjects.foo; Schema<Foo> schema2 = RuntimeSchema.getSchema(Foo.class); Schema<io.protostuff.Foo> schema3 = RuntimeSchema .getSchema(io.protostuff.Foo.class); byte[] byte1 = ProtostuffIOUtil.toByteArray(foo1, schema1, buf()); byte[] byte2 = ProtostuffIOUtil.toByteArray(foo2, schema2, buf()); byte[] byte3 = ProtostuffIOUtil.toByteArray(foo1, schema3, buf()); assertArrayEquals(byte1, byte2); assertArrayEquals(byte1, byte3); }