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);
}
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) {
}
}
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);
}
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);
}
Aggregations