use of okio.ByteString in project wire by square.
the class ParseTest method typeMismatchHonorsWireDeclaredType.
@Ignore("TODO(jwilson)")
@Test
public void typeMismatchHonorsWireDeclaredType() throws Exception {
// tag 1 / 3-byte length-delimited string: 0x109506
// (0x109506 is a well-formed proto message that sets tag 2 to 456).
ByteString data = ByteString.decodeHex("0a03109506");
OneField oneField = OneField.ADAPTER.decode(data.toByteArray());
assertThat(oneField).isEqualTo(new OneField.Builder().opt_int32(3).build());
}
use of okio.ByteString in project wire by square.
the class ParseTest method unknownTagIgnored.
@Test
public void unknownTagIgnored() throws Exception {
// tag 1 / type 0: 456
// tag 2 / type 0: 789
ByteString data = ByteString.decodeHex("08c803109506");
OneField oneField = OneField.ADAPTER.decode(data.toByteArray());
OneField expected = new OneField.Builder().opt_int32(456).build();
assertThat(oneField).isNotEqualTo(expected);
assertThat(oneField.withoutUnknownFields()).isEqualTo(expected);
}
use of okio.ByteString in project wire by square.
the class ParseTest method unknownTypeThrowsIOException.
@Test
public void unknownTypeThrowsIOException() throws Exception {
// tag 1 / type 0: 456
// tag 2 / type 7: 789
ByteString data = ByteString.decodeHex("08c803179506");
try {
OneField.ADAPTER.decode(data.toByteArray());
fail();
} catch (ProtocolException expected) {
assertThat(expected).hasMessage("Unexpected field encoding: 7");
}
}
use of okio.ByteString in project wire by square.
the class ParseTest method repeatedUnknownValueWithDifferentTypesThrowsIOException.
@Ignore("we no longer enforce this constraint")
@Test
public void repeatedUnknownValueWithDifferentTypesThrowsIOException() throws Exception {
// tag 2 / 3-byte length-delimited string: 0x109506
// tag 2 / type 0: 456
ByteString data = ByteString.decodeHex("120300000010c803");
try {
OneField.ADAPTER.decode(data.toByteArray());
fail();
} catch (ProtocolException expected) {
assertThat(expected).hasMessage("Wire type VARINT differs from previous type LENGTH_DELIMITED for tag 2");
}
}
use of okio.ByteString in project wire by square.
the class ParseTest method overRecursionLimitThrowsIOException.
@Test
public void overRecursionLimitThrowsIOException() throws Exception {
// tag 2: nested message (65 times)
// tag 1: signed varint32 456
ByteString data = ByteString.decodeHex("128001127e127c127a12781276127412721270126e126c126a12681" + "266126412621260125e125c125a12581256125412521250124e124c124a12481246124412421240123e123c1" + "23a12381236123412321230122e122c122a12281226122412221220121e121c121a121812161214121212101" + "20e120c120a1208120612041202120008c803");
try {
Recursive.ADAPTER.decode(data.toByteArray());
fail();
} catch (IOException expected) {
assertThat(expected).hasMessage("Wire recursion limit exceeded");
}
}
Aggregations