use of com.squareup.wire.protos.simple.ExternalMessage in project wire by square.
the class WireTest method testExtensionEnum.
@Test
public void testExtensionEnum() throws Exception {
ExternalMessage optional_external_msg = new ExternalMessage.Builder().nested_enum_ext(SimpleMessage.NestedEnum.BAZ).build();
SimpleMessage msg = new SimpleMessage.Builder().optional_external_msg(optional_external_msg).required_int32(456).build();
ProtoAdapter<SimpleMessage> adapter = SimpleMessage.ADAPTER;
byte[] data = adapter.encode(msg);
// Change BAZ enum to a value not known by this client.
data[4] = 17;
// Parse the altered message.
SimpleMessage newMsg = adapter.decode(data);
// Original value shows up as an extension.
assertThat(msg.toString()).contains("nested_enum_ext=BAZ");
// New value is unknown in the tag map.
ProtoReader reader = new ProtoReader(new Buffer().write(newMsg.optional_external_msg.unknownFields()));
reader.beginMessage();
assertThat(reader.nextTag()).isEqualTo(129);
assertThat(reader.peekFieldEncoding().rawProtoAdapter().decode(reader)).isEqualTo(17L);
// Serialized outputs are the same.
byte[] newData = adapter.encode(newMsg);
assertThat(data).isEqualTo(newData);
}
use of com.squareup.wire.protos.simple.ExternalMessage in project wire by square.
the class WireTest method testExtensionsNoRegistry.
@Test
public void testExtensionsNoRegistry() throws Exception {
ExternalMessage optional_external_msg = new ExternalMessage.Builder().fooext(Arrays.asList(444, 555)).barext(333).bazext(222).build();
SimpleMessage msg = new SimpleMessage.Builder().optional_external_msg(optional_external_msg).required_int32(456).build();
assertThat(msg.optional_external_msg.fooext).containsExactly(444, 555);
assertThat(msg.optional_external_msg.barext).isEqualTo(new Integer(333));
assertThat(msg.optional_external_msg.bazext).isEqualTo(new Integer(222));
ProtoAdapter<SimpleMessage> adapter = SimpleMessage.ADAPTER;
byte[] result = adapter.encode(msg);
assertThat(result.length).isEqualTo(21);
SimpleMessage newMsg = adapter.decode(result);
assertThat(newMsg.optional_external_msg.fooext).isEqualTo(Arrays.asList(444, 555));
assertThat(newMsg.optional_external_msg.barext).isEqualTo(333);
assertThat(newMsg.optional_external_msg.bazext).isEqualTo(222);
}
use of com.squareup.wire.protos.simple.ExternalMessage in project wire by square.
the class WireTest method testExtensions.
@Test
public void testExtensions() throws Exception {
ExternalMessage optional_external_msg = new ExternalMessage.Builder().fooext(Arrays.asList(444, 555)).barext(333).bazext(222).nested_message_ext(new SimpleMessage.NestedMessage.Builder().bb(77).build()).nested_enum_ext(SimpleMessage.NestedEnum.BAZ).build();
SimpleMessage msg = new SimpleMessage.Builder().optional_external_msg(optional_external_msg).required_int32(456).build();
assertThat(msg.optional_external_msg.fooext).containsExactly(444, 555);
assertThat(msg.optional_external_msg.barext).isEqualTo(new Integer(333));
assertThat(msg.optional_external_msg.bazext).isEqualTo(new Integer(222));
assertThat(msg.optional_external_msg.nested_message_ext.bb).isEqualTo(new Integer(77));
assertThat(msg.optional_external_msg.nested_enum_ext).isEqualTo(SimpleMessage.NestedEnum.BAZ);
ProtoAdapter<SimpleMessage> adapter = SimpleMessage.ADAPTER;
byte[] result = adapter.encode(msg);
assertThat(result.length).isEqualTo(29);
SimpleMessage newMsg = adapter.decode(result);
assertThat(newMsg.optional_external_msg.fooext).containsExactly(444, 555);
assertThat(newMsg.optional_external_msg.barext).isEqualTo(new Integer(333));
assertThat(newMsg.optional_external_msg.bazext).isEqualTo(new Integer(222));
}
Aggregations