@Override protected <T> byte[] toByteArray(T message, Schema<T> schema) { return ProtobufIOUtil.toByteArray(message, schema, buf()); }
@Override protected <T> byte[] toByteArray(T message, Schema<T> schema) { return ProtobufIOUtil.toByteArray(message, schema, buf()); }
@Override protected <T> byte[] toByteArray(T message, Schema<T> schema) { return ProtobufIOUtil.toByteArray(message, schema, buf()); }
@Override protected <T> byte[] toByteArray(T message, Schema<T> schema) { return ProtobufIOUtil.toByteArray(message, schema, buf()); }
@Override protected <T> byte[] toByteArray(T message, Schema<T> schema) { return ProtobufIOUtil.toByteArray(message, schema, buf()); }
@Override public <T extends Map<String, String>> byte[] toByteArray(T message, Schema<T> schema) throws IOException { return ProtobufIOUtil.toByteArray(message, schema, buf()); }
@Override protected <T> byte[] toByteArray(T message, Schema<T> schema) { return ProtobufIOUtil.toByteArray(message, schema, buf()); }
public void testProtobuf() throws Exception { Schema<Entity> schema = RuntimeSchema.getSchema(Entity.class); Entity p = filledEntity(); byte[] data = ProtobufIOUtil.toByteArray(p, schema, LinkedBuffer.allocate(512)); Entity p2 = new Entity(); ProtostuffIOUtil.mergeFrom(data, p2, schema); assertEquals(p, p2); List<Entity> list = new ArrayList<Entity>(); list.add(p); list.add(p2); ByteArrayOutputStream out = new ByteArrayOutputStream(); ProtobufIOUtil.writeListTo(out, list, schema, buf()); byte[] listData = out.toByteArray(); ByteArrayInputStream in = new ByteArrayInputStream(listData); List<Entity> parsedList = ProtobufIOUtil.parseListFrom(in, schema); assertEquals(list, parsedList); }
public void testProtobuf() throws Exception { Schema<Zoo> schema = RuntimeSchema.getSchema(Zoo.class); Zoo p = filledZoo(); byte[] data = ProtobufIOUtil.toByteArray(p, schema, buf()); // System.err.println("protobuf: " + data.length); Zoo p2 = new Zoo(); ProtobufIOUtil.mergeFrom(data, p2, schema); assertEquals(p, p2); List<Zoo> list = new ArrayList<Zoo>(); list.add(p); list.add(p2); ByteArrayOutputStream out = new ByteArrayOutputStream(); ProtobufIOUtil.writeListTo(out, list, schema, buf()); byte[] listData = out.toByteArray(); ByteArrayInputStream in = new ByteArrayInputStream(listData); List<Zoo> parsedList = ProtobufIOUtil.parseListFrom(in, schema); assertEquals(list, parsedList); }
static <T> void protobufRoundTrip(T message, Schema<T> schema, Pipe.Schema<T> pipeSchema) throws Exception { byte[] protobuf = ProtobufIOUtil.toByteArray(message, schema, buf()); ByteArrayInputStream protobufStream = new ByteArrayInputStream(protobuf); byte[] smile = SmileIOUtil.toByteArray( ProtobufIOUtil.newPipe(protobuf, 0, protobuf.length), pipeSchema, false); byte[] smileFromStream = SmileIOUtil.toByteArray( ProtobufIOUtil.newPipe(protobufStream), pipeSchema, false); assertTrue(Arrays.equals(smile, smileFromStream)); T parsedMessage = schema.newMessage(); SmileIOUtil.mergeFrom(smile, parsedMessage, schema, false); SerializableObjects.assertEquals(message, parsedMessage); ByteArrayInputStream smileStream = new ByteArrayInputStream(smile); byte[] protobufRoundTrip = ProtobufIOUtil.toByteArray( SmileIOUtil.newPipe(smile, 0, smile.length, false), pipeSchema, buf()); byte[] protobufRoundTripFromStream = ProtobufIOUtil.toByteArray( SmileIOUtil.newPipe(smileStream, false), pipeSchema, buf()); assertTrue(Arrays.equals(protobufRoundTrip, protobufRoundTripFromStream)); assertTrue(Arrays.equals(protobufRoundTrip, protobuf)); }
public void testProtobuf() throws Exception { Schema<Payment> schema = RuntimeSchema.getSchema(Payment.class); Payment p = filledPayment(); byte[] data = ProtobufIOUtil.toByteArray(p, schema, buf()); Payment p2 = new Payment(); ProtobufIOUtil.mergeFrom(data, p2, schema); /* * System.err.println(p2.getId()); System.err.println(p2.getBd()); System.err.println(p2.getBi()); * System.err.println(p2.getBdList()); System.err.println(p2.getBiList()); */ assertEquals(p, p2); List<Payment> list = new ArrayList<Payment>(); list.add(p); list.add(p2); ByteArrayOutputStream out = new ByteArrayOutputStream(); ProtobufIOUtil.writeListTo(out, list, schema, buf()); byte[] listData = out.toByteArray(); ByteArrayInputStream in = new ByteArrayInputStream(listData); List<Payment> parsedList = ProtobufIOUtil.parseListFrom(in, schema); assertEquals(list, parsedList); }
@Override protected <T> void roundTrip(T message, Schema<T> schema, Pipe.Schema<T> pipeSchema) throws Exception { byte[] protobuf = ProtobufIOUtil.toByteArray(message, schema, buf()); ByteArrayInputStream protobufStream = new ByteArrayInputStream(protobuf); byte[] protostuff = ProtostuffIOUtil.toByteArray( ProtobufIOUtil.newPipe(protobuf, 0, protobuf.length), pipeSchema, buf()); byte[] protostuffFromStream = ProtostuffIOUtil.toByteArray( ProtobufIOUtil.newPipe(protobufStream), pipeSchema, buf()); assertTrue(Arrays.equals(protostuff, protostuffFromStream)); T parsedMessage = schema.newMessage(); ProtostuffIOUtil.mergeFrom(protostuff, parsedMessage, schema); SerializableObjects.assertEquals(message, parsedMessage); ByteArrayInputStream protostuffStream = new ByteArrayInputStream( protostuff); byte[] protobufRoundTrip = ProtobufIOUtil.toByteArray( ProtostuffIOUtil.newPipe(protostuff, 0, protostuff.length), pipeSchema, buf()); byte[] protobufRoundTripFromStream = ProtobufIOUtil.toByteArray( ProtostuffIOUtil.newPipe(protostuffStream), pipeSchema, buf()); assertTrue(Arrays.equals(protobufRoundTrip, protobufRoundTripFromStream)); assertTrue(Arrays.equals(protobufRoundTrip, protobuf)); }
static void verifyProtobuf(PojoWithInts p) throws IOException { Schema<PojoWithInts> schema = PojoWithInts.getSchema(); byte[] data = ProtobufIOUtil.toByteArray(p, schema, buf()); PojoWithInts pFromByteArray = new PojoWithInts(); ProtobufIOUtil.mergeFrom(data, pFromByteArray, schema); assertEquals(p, pFromByteArray); ByteArrayOutputStream out = new ByteArrayOutputStream(); ProtobufIOUtil.writeTo(out, p, schema, buf()); byte[] dataFromStream = out.toByteArray(); assertTrue(Arrays.equals(data, dataFromStream)); ByteArrayInputStream in = new ByteArrayInputStream(data); PojoWithInts pFromStream = new PojoWithInts(); ProtobufIOUtil.mergeFrom(in, pFromStream, schema); assertEquals(p, pFromStream); }
static <T> void protobufRoundTrip(T message, Schema<T> schema, Pipe.Schema<T> pipeSchema) throws Exception { byte[] protobuf = ProtobufIOUtil.toByteArray(message, schema, buf()); ByteArrayInputStream protobufStream = new ByteArrayInputStream(protobuf); byte[] msgpack = MsgpackIOUtil.toByteArray( ProtobufIOUtil.newPipe(protobuf, 0, protobuf.length), pipeSchema, numeric); byte[] msgpackFromStream = MsgpackIOUtil.toByteArray( ProtobufIOUtil.newPipe(protobufStream), pipeSchema, numeric); assertTrue(msgpack.length == msgpackFromStream.length); assertEquals(STRING.deser(msgpack), STRING.deser(msgpackFromStream)); T parsedMessage = schema.newMessage(); MsgpackIOUtil.mergeFrom(msgpack, parsedMessage, schema, numeric); SerializableObjects.assertEquals(message, parsedMessage); ByteArrayInputStream jsonStream = new ByteArrayInputStream(msgpack); byte[] protobufRoundTrip = ProtobufIOUtil.toByteArray( MsgpackIOUtil.newPipe(msgpack, 0, msgpack.length, numeric), pipeSchema, buf()); byte[] protobufRoundTripFromStream = ProtobufIOUtil.toByteArray( MsgpackIOUtil.newPipe(jsonStream, numeric), pipeSchema, buf()); assertTrue(Arrays.equals(protobufRoundTrip, protobufRoundTripFromStream)); assertTrue(Arrays.equals(protobufRoundTrip, protobuf)); }
static <T> void protobufRoundTrip(T message, Schema<T> schema, Pipe.Schema<T> pipeSchema) throws Exception { byte[] protobuf = ProtobufIOUtil.toByteArray(message, schema, buf()); ByteArrayInputStream protobufStream = new ByteArrayInputStream(protobuf); byte[] xml = XmlIOUtil.toByteArray( ProtobufIOUtil.newPipe(protobuf, 0, protobuf.length), pipeSchema); byte[] xmlFromStream = XmlIOUtil.toByteArray( ProtobufIOUtil.newPipe(protobufStream), pipeSchema); assertTrue(xml.length == xmlFromStream.length); assertEquals(STRING.deser(xml), STRING.deser(xmlFromStream)); T parsedMessage = schema.newMessage(); XmlIOUtil.mergeFrom(xml, parsedMessage, schema); SerializableObjects.assertEquals(message, parsedMessage); ByteArrayInputStream xmlStream = new ByteArrayInputStream(xml); byte[] protobufRoundTrip = ProtobufIOUtil.toByteArray( XmlIOUtil.newPipe(xml, 0, xml.length), pipeSchema, buf()); byte[] protobufRoundTripFromStream = ProtobufIOUtil.toByteArray( XmlIOUtil.newPipe(xmlStream), pipeSchema, buf()); assertTrue(Arrays.equals(protobufRoundTrip, protobufRoundTripFromStream)); assertTrue(Arrays.equals(protobufRoundTrip, protobuf)); }
static <T> void protobufRoundTrip(T message, Schema<T> schema, Pipe.Schema<T> pipeSchema, boolean numeric) throws Exception { byte[] protobuf = ProtobufIOUtil.toByteArray(message, schema, buf()); ByteArrayInputStream protobufStream = new ByteArrayInputStream(protobuf); byte[] json = JsonIOUtil.toByteArray( ProtobufIOUtil.newPipe(protobuf, 0, protobuf.length), pipeSchema, numeric); byte[] jsonFromStream = JsonIOUtil.toByteArray( ProtobufIOUtil.newPipe(protobufStream), pipeSchema, numeric); assertTrue(json.length == jsonFromStream.length); assertEquals(STRING.deser(json), STRING.deser(jsonFromStream)); T parsedMessage = schema.newMessage(); JsonIOUtil.mergeFrom(json, parsedMessage, schema, numeric); SerializableObjects.assertEquals(message, parsedMessage); ByteArrayInputStream jsonStream = new ByteArrayInputStream(json); byte[] protobufRoundTrip = ProtobufIOUtil.toByteArray( JsonIOUtil.newPipe(json, 0, json.length, numeric), pipeSchema, buf()); byte[] protobufRoundTripFromStream = ProtobufIOUtil.toByteArray( JsonIOUtil.newPipe(jsonStream, numeric), pipeSchema, buf()); assertTrue(Arrays.equals(protobufRoundTrip, protobufRoundTripFromStream)); assertTrue(Arrays.equals(protobufRoundTrip, protobuf)); checkCompat(json, jsonFromStream, protobuf, pipeSchema, numeric, false); }
public static <T> void roundTrip(T message, Schema<T> schema, Pipe.Schema<T> pipeSchema) throws Exception { byte[] protobuf = ProtobufIOUtil.toByteArray(message, schema, buf()); ByteArrayInputStream protobufStream = new ByteArrayInputStream(protobuf); byte[] protostuff = ProtostuffIOUtil.toByteArray( ProtobufIOUtil.newPipe(protobuf, 0, protobuf.length), pipeSchema, buf()); byte[] protostuffFromStream = ProtostuffIOUtil.toByteArray( ProtobufIOUtil.newPipe(protobufStream), pipeSchema, buf()); assertTrue(protostuff.length == protostuffFromStream.length); assertTrue(Arrays.equals(protostuff, protostuffFromStream)); T parsedMessage = schema.newMessage(); ProtostuffIOUtil.mergeFrom(protostuff, parsedMessage, schema); SerializableObjects.assertEquals(message, parsedMessage); ByteArrayInputStream protostuffStream = new ByteArrayInputStream(protostuff); byte[] protobufRoundTrip = ProtobufIOUtil.toByteArray( ProtostuffIOUtil.newPipe(protostuff, 0, protostuff.length), pipeSchema, buf()); byte[] protobufRoundTripFromStream = ProtobufIOUtil.toByteArray( ProtostuffIOUtil.newPipe(protostuffStream), pipeSchema, buf()); assertTrue(protobufRoundTrip.length == protobufRoundTripFromStream.length); assertTrue(Arrays.equals(protobufRoundTrip, protobufRoundTripFromStream)); assertTrue(protobufRoundTrip.length == protobuf.length); assertTrue(Arrays.equals(protobufRoundTrip, protobuf)); }
static <T> void protobufRoundTrip(T message, Schema<T> schema, Pipe.Schema<T> pipeSchema) throws Exception { byte[] protobuf = ProtobufIOUtil.toByteArray(message, schema, buf()); ByteArrayInputStream protobufStream = new ByteArrayInputStream(protobuf); byte[] yaml = YamlIOUtil.toByteArray( ProtobufIOUtil.newPipe(protobuf, 0, protobuf.length), pipeSchema, buf()); byte[] yamlFromStream = YamlIOUtil.toByteArray( ProtobufIOUtil.newPipe(protobufStream), pipeSchema, buf()); assertTrue(yaml.length == yamlFromStream.length); String strYaml = STRING.deser(yaml); String strYamlFromStream = STRING.deser(yamlFromStream); assertEquals(strYaml, strYamlFromStream); }
public void testNestedOverflow() { final int bufSize = 256; final Bar bar = new Bar(); // reserve 3 bytes: // 1st: tag // 2nd and 3rd: delimited length (greater than 127 takes to more than one byte) int repeat = bufSize - 3; bar.setSomeString(repeatChar('a', repeat)); byte[] data = ProtobufIOUtil.toByteArray(bar, bar.cachedSchema(), buf(bufSize)); assertEquals(bufSize, data.length); // additional size will be: // 1 (tag) // 1 (delimiter) // 1 + 1 = tag + value (10) // 1 + 1 + 3 = tag + delim + value ("baz") // 1 + 1 = tag + value (15) // ===== // 11 bar.setSomeBaz(new Baz(10, "baz", 15l)); data = ProtobufIOUtil.toByteArray(bar, bar.cachedSchema(), buf(bufSize)); assertEquals(bufSize + 11, data.length); final Bar parsedBar = new Bar(); ProtobufIOUtil.mergeFrom(data, parsedBar, parsedBar.cachedSchema()); assertEquals(bar, parsedBar); }
public void testNestedLarge() { final int bufSize = 256; final Bar bar = new Bar(); // nested message size will be: // 1 + 1 = tag + value (10) // 1 + 1 + 125 = tag + delim + value ("baz") // 1 + 1 = tag + value (15) // ===== // 131 bar.setSomeBaz(new Baz(10, repeatChar('b', 125), 15l)); // size will be: // 1 (tag) // 2 (delimited length) (nested message size is greater than 127) // 131 (nested message size) // ===== // 134 byte[] data = ProtobufIOUtil.toByteArray(bar, bar.cachedSchema(), buf(bufSize)); assertEquals(134, data.length); final Bar parsedBar = new Bar(); ProtobufIOUtil.mergeFrom(data, parsedBar, parsedBar.cachedSchema()); assertEquals(bar, parsedBar); }