Search in sources :

Example 16 with ByteString

use of okio.ByteString in project wire by square.

the class SerializableTest method decodeGolden.

@Test
public void decodeGolden() throws Exception {
    SimpleMessage goldenValue = new SimpleMessage.Builder().required_int32(99).result("tacos").build();
    ByteString goldenSerialized = ByteString.decodeBase64("rO0ABXNyACdjb20uc3F1YXJldXAud2lyZS5NZXNz" + "YWdlU2VyaWFsaXplZEZvcm0AAAAAAAAAAAIAAlsABWJ5dGVzdAACW0JMAAxtZXNzYWdlQ2xhc3N0ABFMamF2YS9s" + "YW5nL0NsYXNzO3hwdXIAAltCrPMX+AYIVOACAAB4cAAAAAkoY1IFdGFjb3N2cgAtY29tLnNxdWFyZXVwLndpcmUu" + "cHJvdG9zLnNpbXBsZS5TaW1wbGVNZXNzYWdlAAAAAAAAAAACAAxMABRkZWZhdWx0X2ZvcmVpZ25fZW51bXQALkxj" + "b20vc3F1YXJldXAvd2lyZS9wcm90b3MvZm9yZWlnbi9Gb3JlaWduRW51bTtMABNkZWZhdWx0X25lc3RlZF9lbnVt" + "dAA6TGNvbS9zcXVhcmV1cC93aXJlL3Byb3Rvcy9zaW1wbGUvU2ltcGxlTWVzc2FnZSROZXN0ZWRFbnVtO0wAF25v" + "X2RlZmF1bHRfZm9yZWlnbl9lbnVtcQB+AAdMAAFvdAASTGphdmEvbGFuZy9TdHJpbmc7TAAVb3B0aW9uYWxfZXh0" + "ZXJuYWxfbXNndAAxTGNvbS9zcXVhcmV1cC93aXJlL3Byb3Rvcy9zaW1wbGUvRXh0ZXJuYWxNZXNzYWdlO0wADm9w" + "dGlvbmFsX2ludDMydAATTGphdmEvbGFuZy9JbnRlZ2VyO0wAE29wdGlvbmFsX25lc3RlZF9tc2d0AD1MY29tL3Nx" + "dWFyZXVwL3dpcmUvcHJvdG9zL3NpbXBsZS9TaW1wbGVNZXNzYWdlJE5lc3RlZE1lc3NhZ2U7TAAFb3RoZXJxAH4A" + "CUwACHBhY2thZ2VfcQB+AAlMAA9yZXBlYXRlZF9kb3VibGV0ABBMamF2YS91dGlsL0xpc3Q7TAAOcmVxdWlyZWRf" + "aW50MzJxAH4AC0wABnJlc3VsdHEAfgAJeHIAGWNvbS5zcXVhcmV1cC53aXJlLk1lc3NhZ2UAAAAAAAAAAAIAAHhw");
    assertThat(deserialize(goldenSerialized)).isEqualTo(goldenValue);
    assertThat(serialize(goldenValue)).isEqualTo(goldenSerialized);
}
Also used : ByteString(okio.ByteString) SimpleMessage(com.squareup.wire.protos.simple.SimpleMessage) Test(org.junit.Test)

Example 17 with ByteString

use of okio.ByteString in project wire by square.

the class TestAllTypes method getBuilder.

private static AllTypes.Builder getBuilder(int numRepeated) {
    ByteString bytes = ByteString.of((byte) 125, (byte) 225);
    AllTypes.NestedMessage nestedMessage = new AllTypes.NestedMessage.Builder().a(999).build();
    return new AllTypes.Builder().opt_int32(111).opt_uint32(112).opt_sint32(113).opt_fixed32(114).opt_sfixed32(115).opt_int64(116L).opt_uint64(117L).opt_sint64(118L).opt_fixed64(119L).opt_sfixed64(120L).opt_bool(true).opt_float(122.0F).opt_double(123.0).opt_string("124").opt_bytes(bytes).opt_nested_enum(A).opt_nested_message(nestedMessage).req_int32(111).req_uint32(112).req_sint32(113).req_fixed32(114).req_sfixed32(115).req_int64(116L).req_uint64(117L).req_sint64(118L).req_fixed64(119L).req_sfixed64(120L).req_bool(true).req_float(122.0F).req_double(123.0).req_string("124").req_bytes(bytes).req_nested_enum(A).req_nested_message(nestedMessage).rep_int32(list(111, numRepeated)).rep_uint32(list(112, numRepeated)).rep_sint32(list(113, numRepeated)).rep_fixed32(list(114, numRepeated)).rep_sfixed32(list(115, numRepeated)).rep_int64(list(116L, numRepeated)).rep_uint64(list(117L, numRepeated)).rep_sint64(list(118L, numRepeated)).rep_fixed64(list(119L, numRepeated)).rep_sfixed64(list(120L, numRepeated)).rep_bool(list(true, numRepeated)).rep_float(list(122.0F, numRepeated)).rep_double(list(123.0, numRepeated)).rep_string(list("124", numRepeated)).rep_bytes(list(bytes, numRepeated)).rep_nested_enum(list(A, numRepeated)).rep_nested_message(list(nestedMessage, numRepeated)).pack_int32(list(111, numRepeated)).pack_uint32(list(112, numRepeated)).pack_sint32(list(113, numRepeated)).pack_fixed32(list(114, numRepeated)).pack_sfixed32(list(115, numRepeated)).pack_int64(list(116L, numRepeated)).pack_uint64(list(117L, numRepeated)).pack_sint64(list(118L, numRepeated)).pack_fixed64(list(119L, numRepeated)).pack_sfixed64(list(120L, numRepeated)).pack_bool(list(true, numRepeated)).pack_float(list(122.0F, numRepeated)).pack_double(list(123.0, numRepeated)).pack_nested_enum(list(A, numRepeated)).ext_opt_bool(true).ext_rep_bool(list(true, numRepeated)).ext_pack_bool(list(true, numRepeated));
}
Also used : ByteString(okio.ByteString) AllTypes(com.squareup.wire.protos.alltypes.AllTypes)

Example 18 with ByteString

use of okio.ByteString in project okhttp by square.

the class Http2Test method assertData.

private Http2Reader.Handler assertData() {
    return new BaseTestHandler() {

        @Override
        public void data(boolean inFinished, int streamId, BufferedSource source, int length) throws IOException {
            assertFalse(inFinished);
            assertEquals(expectedStreamId, streamId);
            assertEquals(1123, length);
            ByteString data = source.readByteString(length);
            for (byte b : data.toByteArray()) {
                assertEquals(2, b);
            }
        }
    };
}
Also used : ByteString(okio.ByteString) BufferedSource(okio.BufferedSource)

Example 19 with ByteString

use of okio.ByteString in project okhttp by square.

the class HpackTest method assertBytes.

private void assertBytes(int... bytes) throws IOException {
    ByteString expected = intArrayToByteArray(bytes);
    ByteString actual = bytesOut.readByteString();
    assertEquals(expected, actual);
}
Also used : ByteString(okio.ByteString)

Example 20 with ByteString

use of okio.ByteString in project okhttp by square.

the class FileOperatorTest method largeWrite.

@Test
public void largeWrite() throws Exception {
    ByteString data = randomByteString(1000000);
    FileOperator operator = new FileOperator(randomAccessFile.getChannel());
    Buffer buffer = new Buffer().write(data);
    operator.write(0, buffer, data.size());
    assertEquals(data, snapshot());
}
Also used : Buffer(okio.Buffer) ByteString(okio.ByteString) Test(org.junit.Test)

Aggregations

ByteString (okio.ByteString)59 Test (org.junit.Test)37 Buffer (okio.Buffer)26 MockResponse (okhttp3.mockwebserver.MockResponse)11 ProtocolException (java.net.ProtocolException)5 IOException (java.io.IOException)4 OneField (com.squareup.wire.protos.edgecases.OneField)3 EOFException (java.io.EOFException)3 BufferedSink (okio.BufferedSink)3 BufferedSource (okio.BufferedSource)3 AllTypes (com.squareup.wire.protos.alltypes.AllTypes)2 Person (com.squareup.wire.protos.person.Person)2 ArrayList (java.util.ArrayList)2 Headers (okhttp3.Headers)2 Request (okhttp3.Request)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 GzipSink (okio.GzipSink)2 Ignore (org.junit.Ignore)2 Phone (retrofit2.converter.protobuf.PhoneProtos.Phone)2 GsonBuilder (com.google.gson.GsonBuilder)1