Search in sources :

Example 11 with ByteString

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());
}
Also used : ByteString(okio.ByteString) OneField(com.squareup.wire.protos.edgecases.OneField) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 12 with ByteString

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);
}
Also used : ByteString(okio.ByteString) OneField(com.squareup.wire.protos.edgecases.OneField) Test(org.junit.Test)

Example 13 with ByteString

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");
    }
}
Also used : ProtocolException(java.net.ProtocolException) ByteString(okio.ByteString) Test(org.junit.Test)

Example 14 with ByteString

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");
    }
}
Also used : ProtocolException(java.net.ProtocolException) ByteString(okio.ByteString) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with ByteString

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");
    }
}
Also used : ByteString(okio.ByteString) IOException(java.io.IOException) 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