Search in sources :

Example 56 with ByteString

use of okio.ByteString in project wire by square.

the class ParseTest method upToRecursionLimit.

@Test
public void upToRecursionLimit() throws Exception {
    // tag 2: nested message (64 times)
    // tag 1: signed varint32 456
    ByteString data = ByteString.decodeHex("127e127c127a12781276127412721270126e126c126a12681266126" + "412621260125e125c125a12581256125412521250124e124c124a12481246124412421240123e123c123a123" + "81236123412321230122e122c122a12281226122412221220121e121c121a12181216121412121210120e120" + "c120a1208120612041202120008c803");
    Recursive recursive = Recursive.ADAPTER.decode(data.toByteArray());
    assertThat(recursive.value.intValue()).isEqualTo(456);
}
Also used : ByteString(okio.ByteString) Recursive(com.squareup.wire.protos.edgecases.Recursive) Test(org.junit.Test)

Example 57 with ByteString

use of okio.ByteString in project wire by square.

the class SchemaProtoAdapterTest method startGroupWithoutEndGroup.

@Test
public void startGroupWithoutEndGroup() throws IOException {
    ProtoAdapter<Object> adapter = new RepoBuilder().add("message.proto", "" + "message Message {\n" + "  optional string a = 1;\n" + "}\n").protoAdapter("Message");
    ByteString encoded = ByteString.decodeHex("130a0161");
    try {
        adapter.decode(new Buffer().write(encoded));
        fail();
    } catch (EOFException expected) {
    }
}
Also used : Buffer(okio.Buffer) ByteString(okio.ByteString) EOFException(java.io.EOFException) Test(org.junit.Test)

Example 58 with ByteString

use of okio.ByteString in project wire by square.

the class SchemaProtoAdapterTest method decodeToPacked.

@Test
public void decodeToPacked() throws IOException {
    ProtoAdapter<Object> adapter = new RepoBuilder().add("message.proto", "" + "message Message {\n" + "  repeated int32 a = 90 [packed = true];\n" + "}\n").protoAdapter("Message");
    ImmutableMap<String, Object> expected = ImmutableMap.<String, Object>of("a", ImmutableList.of(601, 701));
    ByteString unpackedEncoded = ByteString.decodeHex("d005d904d005bd05");
    assertThat(adapter.decode(new Buffer().write(unpackedEncoded))).isEqualTo(expected);
    ByteString packedEncoded = ByteString.decodeHex("d20504d904bd05");
    assertThat(adapter.decode(new Buffer().write(packedEncoded))).isEqualTo(expected);
}
Also used : Buffer(okio.Buffer) ByteString(okio.ByteString) ByteString(okio.ByteString) Test(org.junit.Test)

Example 59 with ByteString

use of okio.ByteString in project wire by square.

the class SchemaProtoAdapterTest method recursiveMessage.

@Test
public void recursiveMessage() throws IOException {
    ProtoAdapter<Object> adapter = new RepoBuilder().add("tree.proto", "" + "message BinaryTreeNode {\n" + "  optional BinaryTreeNode left = 1;\n" + "  optional BinaryTreeNode right = 2;\n" + "  optional string value = 3;\n" + "}\n").protoAdapter("BinaryTreeNode");
    ImmutableMap<String, Object> value = ImmutableMap.<String, Object>of("value", "D", "left", ImmutableMap.of("value", "B", "left", ImmutableMap.of("value", "A"), "right", ImmutableMap.of("value", "C")), "right", ImmutableMap.of("value", "F", "left", ImmutableMap.of("value", "E"), "right", ImmutableMap.of("value", "G")));
    ByteString encoded = ByteString.decodeHex("1a01440a0d1a01420a031a014112031a0143120d1a01460a031a014512031a0147");
    assertThat(ByteString.of(adapter.encode(value))).isEqualTo(encoded);
    assertThat(adapter.decode(new Buffer().write(encoded))).isEqualTo(value);
}
Also used : Buffer(okio.Buffer) ByteString(okio.ByteString) 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