@Override public ByteString readBytes() throws IOException { return ByteString.wrap(readByteArray()); }
@Override public ByteString readBytes() throws IOException { return ByteString.wrap(readByteArray()); }
@Override public ByteString readBytes() throws IOException { return ByteString.wrap(parser.parsePayload()); }
@Override public ByteString readBytes() throws IOException { return ByteString.wrap(readByteArray()); }
@Override public ByteString readBytes() throws IOException { return ByteString.wrap(readByteArray()); }
@Override public ByteString readBytes() throws IOException { return ByteString.wrap(readByteArray()); }
@Override public ByteString readBytes() throws IOException { return ByteString.wrap(readByteArray()); }
/** * Read a {@code bytes} field value from the stream. */ @Override public ByteString readBytes() throws IOException { final int size = readRawVarint32(); if (size == 0) { return ByteString.EMPTY; } if (size <= (bufferSize - bufferPos) && size > 0) { // Fast path: We already have the bytes in a contiguous buffer, so // just copy directly from it. final ByteString result = ByteString.copyFrom(buffer, bufferPos, size); bufferPos += size; return result; } else { // Slow path: Build a byte array first then copy it. // return ByteString.copyFrom(readRawBytes(size)); return ByteString.wrap(readRawBytes(size)); } }
public void testCompareVsOther() throws Exception { Baz aBaz = new Baz(1, "hello world", 1238372479L); ByteBuffer serForm1 = testObj(aBaz, aBaz); deserTest(aBaz, aBaz, serForm1); Bar testBar = new Bar(22, "some String", aBaz, Bar.Status.COMPLETED, ByteString.wrap("fuck yo test".getBytes()), false, 3.14f, 2.7182818284, 599L ); ByteBuffer serForm2 = testObj(testBar, testBar); deserTest(testBar, testBar, serForm2); }
public void testCompareVsOther() throws Exception { Baz aBaz = new Baz(1, "hello world", 1238372479L); ByteBuffer serForm1 = testObj(aBaz, aBaz); deserTest(aBaz, aBaz, serForm1); Bar testBar = new Bar(22, "some String", aBaz, Bar.Status.COMPLETED, ByteString.wrap("fuck yo test".getBytes()), false, 3.14f, 2.7182818284, 599L ); ByteBuffer serForm2 = testObj(testBar, testBar); deserTest(testBar, testBar, serForm2); }
public void testBarTooLarge2() throws Exception { Schema<Bar> schema = Bar.getSchema(); Bar message = new Bar(); message.setSomeBytes(ByteString.wrap( new byte[StringSerializer.THREE_BYTE_LOWER_LIMIT - 1])); 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); Bar parsedMessage = schema.newMessage(); boolean merged = optMergeDelimitedFrom(in, parsedMessage, schema, buf(256)); assertFalse(merged); }
public void testBarTooLarge3() throws Exception { Schema<Bar> schema = Bar.getSchema(); Bar message = new Bar(); message.setSomeBytes(ByteString.wrap( new byte[StringSerializer.FOUR_BYTE_LOWER_LIMIT - 1])); 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); Bar parsedMessage = schema.newMessage(); boolean merged = optMergeDelimitedFrom(in, parsedMessage, schema, buf(256)); assertFalse(merged); } }
@Override public ByteString readBytes() throws IOException { return ByteString.wrap(readByteArray()); }
@Override public ByteString readBytes() throws IOException { return ByteString.wrap(readByteArray()); }
@Override public ByteString readBytes() throws IOException { return ByteString.wrap(readByteArray()); }