Search in sources :

Example 1 with AllTypes

use of com.squareup.wire.protos.alltypes.AllTypes in project wire by square.

the class TestAllTypes method testReadSource.

@Test
public void testReadSource() throws IOException {
    byte[] data = adapter.encode(allTypes);
    Buffer input = new Buffer().write(data);
    AllTypes parsed = adapter.decode(input);
    assertThat(parsed).isEqualTo(allTypes);
    assertThat(allTypes.ext_opt_bool).isEqualTo(Boolean.TRUE);
    assertThat(allTypes.ext_rep_bool).isEqualTo(list(true));
    assertThat(allTypes.ext_pack_bool).isEqualTo(list(true));
}
Also used : Buffer(okio.Buffer) AllTypes(com.squareup.wire.protos.alltypes.AllTypes) Test(org.junit.Test)

Example 2 with AllTypes

use of com.squareup.wire.protos.alltypes.AllTypes in project wire by square.

the class TestAllTypes method testReadNonPacked.

@Test
public void testReadNonPacked() throws IOException {
    AllTypes parsed = adapter.decode(new Buffer().write(TestAllTypesData.nonPacked));
    assertThat(parsed).isEqualTo(allTypes);
}
Also used : Buffer(okio.Buffer) AllTypes(com.squareup.wire.protos.alltypes.AllTypes) Test(org.junit.Test)

Example 3 with AllTypes

use of com.squareup.wire.protos.alltypes.AllTypes in project wire by square.

the class TestAllTypes method testUnknownFields.

@Test
public void testUnknownFields() {
    AllTypes.Builder builder = getBuilder();
    builder.addUnknownField(10000, FieldEncoding.VARINT, 1L);
    AllTypes withUnknownField = builder.build();
    byte[] data = adapter.encode(withUnknownField);
    int count = TestAllTypesData.expectedOutput.size();
    assertThat(data.length).isEqualTo(count + 4);
    assertThat(data[count]).isEqualTo((byte) 0x80);
    assertThat(data[count + 1]).isEqualTo((byte) 0xf1);
    assertThat(data[count + 2]).isEqualTo((byte) 0x04);
    assertThat(data[count + 3]).isEqualTo((byte) 0x01);
}
Also used : AllTypes(com.squareup.wire.protos.alltypes.AllTypes) Test(org.junit.Test)

Example 4 with AllTypes

use of com.squareup.wire.protos.alltypes.AllTypes in project wire by square.

the class TestAllTypes method testSkipGroup.

@Test
public void testSkipGroup() throws IOException {
    byte[] data = new byte[TestAllTypesData.expectedOutput.size() + 27];
    System.arraycopy(TestAllTypesData.expectedOutput.toByteArray(), 0, data, 0, 17);
    int index = 17;
    // start group, tag = 20, type = 3
    data[index++] = (byte) 0xa3;
    data[index++] = (byte) 0x01;
    // tag = 1, type = 0 (varint)
    data[index++] = (byte) 0x08;
    data[index++] = (byte) 0x81;
    data[index++] = (byte) 0x82;
    data[index++] = (byte) 0x6f;
    // tag = 2, type = 1 (fixed64)
    data[index++] = (byte) 0x21;
    data[index++] = (byte) 0x01;
    data[index++] = (byte) 0x02;
    data[index++] = (byte) 0x03;
    data[index++] = (byte) 0x04;
    data[index++] = (byte) 0x05;
    data[index++] = (byte) 0x06;
    data[index++] = (byte) 0x07;
    data[index++] = (byte) 0x08;
    // tag = 3, type = 2 (length-delimited)
    data[index++] = (byte) 0x1a;
    // length = 3
    data[index++] = (byte) 0x03;
    data[index++] = (byte) 0x01;
    data[index++] = (byte) 0x02;
    data[index++] = (byte) 0x03;
    // tag = 4, type = 5 (fixed32)
    data[index++] = (byte) 0x25;
    data[index++] = (byte) 0x01;
    data[index++] = (byte) 0x02;
    data[index++] = (byte) 0x03;
    data[index++] = (byte) 0x04;
    // end group, tag = 20, type = 4
    data[index++] = (byte) 0xa4;
    data[index++] = (byte) 0x01;
    System.arraycopy(TestAllTypesData.expectedOutput.toByteArray(), 17, data, index, TestAllTypesData.expectedOutput.size() - 17);
    AllTypes parsed = adapter.decode(data);
    assertThat(parsed).isEqualTo(allTypes);
}
Also used : AllTypes(com.squareup.wire.protos.alltypes.AllTypes) Test(org.junit.Test)

Example 5 with AllTypes

use of com.squareup.wire.protos.alltypes.AllTypes in project wire by square.

the class TestAllTypes method testReadBytes.

@Test
public void testReadBytes() throws IOException {
    byte[] data = adapter.encode(allTypes);
    AllTypes parsed = adapter.decode(data);
    assertThat(parsed).isEqualTo(allTypes);
    assertThat(allTypes.ext_opt_bool).isEqualTo(Boolean.TRUE);
    assertThat(allTypes.ext_rep_bool).isEqualTo(list(true));
    assertThat(allTypes.ext_pack_bool).isEqualTo(list(true));
}
Also used : AllTypes(com.squareup.wire.protos.alltypes.AllTypes) Test(org.junit.Test)

Aggregations

AllTypes (com.squareup.wire.protos.alltypes.AllTypes)14 Test (org.junit.Test)14 Buffer (okio.Buffer)3 ByteString (okio.ByteString)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ForwardingSource (okio.ForwardingSource)1 Source (okio.Source)1