예제 #1
0
  @Test
  public void testMessageOptions() {
    FooBar option_one =
        MessageWithOptions.MESSAGE_OPTIONS.getExtension(Ext_custom_options.my_message_option_one);
    Assert.assertEquals(new Integer(1234), option_one.foo);
    Assert.assertEquals("5678", option_one.bar);
    FooBar.Nested baz1 = option_one.baz;
    Assert.assertEquals(BAZ, baz1.value);
    long expected = new BigInteger("18446744073709551615").longValue();
    Assert.assertEquals(-1L, expected); // unsigned value in .proto file is wrapped
    Assert.assertEquals(Long.valueOf(expected), option_one.qux);
    Assert.assertEquals(2, option_one.fred.size());
    Assert.assertEquals(123.0F, option_one.fred.get(0), 0.0000001);
    Assert.assertEquals(321, option_one.fred.get(1), 0.0000001);
    Assert.assertEquals(456.0, option_one.daisy, 0.0000001);

    double option_two =
        MessageWithOptions.MESSAGE_OPTIONS.getExtension(Ext_custom_options.my_message_option_two);
    Assert.assertEquals(91011.0F, option_two, 0.0000001);

    FooBar option_three =
        MessageWithOptions.MESSAGE_OPTIONS.getExtension(Ext_custom_options.my_message_option_three);
    Assert.assertEquals(new Integer(11), option_three.foo);
    Assert.assertEquals("22", option_three.bar);
    FooBar.Nested baz3 = option_three.baz;
    Assert.assertEquals(BAR, baz3.value);
    Assert.assertEquals(2, option_three.fred.size());
    Assert.assertEquals(444.0F, option_three.fred.get(0), 0.0000001);
    Assert.assertEquals(555.0F, option_three.fred.get(1), 0.0000001);
    Assert.assertNotNull(option_three.nested);
    Assert.assertEquals(1, option_three.nested.size());
    Assert.assertEquals(new Integer(33), option_three.nested.get(0).foo);

    ForeignMessage foreign_option =
        MessageWithOptions.MESSAGE_OPTIONS.getExtension(Ext_foreign.foreign_message_option);
    Assert.assertEquals(new Integer(9876), foreign_option.i);

    FooBar.FooBarBazEnum option_four =
        MessageWithOptions.MESSAGE_OPTIONS.getExtension(Ext_custom_options.my_message_option_four);
    Assert.assertEquals(FOO, option_four);

    FooBar option_five =
        MessageWithOptions.MESSAGE_OPTIONS.getExtension(Ext_custom_options.my_message_option_five);
    Assert.assertEquals(BAZ, option_five.getExtension(Ext_custom_options.ext));
    Assert.assertEquals(Arrays.asList(FOO, BAZ), option_five.getExtension(Ext_custom_options.rep));

    Assert.assertEquals(new Integer(17), FooBar.FooBarBazEnum.FOO.enum_value_option);
    Assert.assertEquals(
        Arrays.asList(99, 199), FooBar.FooBarBazEnum.FOO.complex_enum_value_option.serial);
    Assert.assertEquals(null, FooBar.FooBarBazEnum.FOO.foreign_enum_value_option);
    Assert.assertEquals(null, FooBar.FooBarBazEnum.BAR.enum_value_option);
    Assert.assertEquals(Boolean.TRUE, FooBar.FooBarBazEnum.BAR.foreign_enum_value_option);
    Assert.assertEquals(new Integer(18), FooBar.FooBarBazEnum.BAZ.enum_value_option);
    Assert.assertEquals(Boolean.FALSE, FooBar.FooBarBazEnum.BAZ.foreign_enum_value_option);

    Assert.assertEquals(
        Boolean.TRUE,
        FooBar.FooBarBazEnum.ENUM_OPTIONS.getExtension(Ext_custom_options.enum_option));
  }
예제 #2
0
파일: FooBar.java 프로젝트: pforhan/wire
 @Override
 public boolean equals(Object other) {
   if (other == this) return true;
   if (!(other instanceof FooBar)) return false;
   FooBar o = (FooBar) other;
   return WireInternal.equals(unknownFields(), o.unknownFields())
       && WireInternal.equals(foo, o.foo)
       && WireInternal.equals(bar, o.bar)
       && WireInternal.equals(baz, o.baz)
       && WireInternal.equals(qux, o.qux)
       && WireInternal.equals(fred, o.fred)
       && WireInternal.equals(daisy, o.daisy)
       && WireInternal.equals(nested, o.nested)
       && WireInternal.equals(ext, o.ext)
       && WireInternal.equals(rep, o.rep);
 }
예제 #3
0
파일: FooBar.java 프로젝트: pforhan/wire
 @Override
 public FooBar redact(FooBar value) {
   Builder builder = value.newBuilder();
   if (builder.baz != null) builder.baz = Nested.ADAPTER.redact(builder.baz);
   WireInternal.redactElements(builder.nested, FooBar.ADAPTER);
   builder.clearUnknownFields();
   return builder.build();
 }
예제 #4
0
파일: FooBar.java 프로젝트: pforhan/wire
 @Override
 public int encodedSize(FooBar value) {
   return (value.foo != null ? ProtoAdapter.INT32.encodedSizeWithTag(1, value.foo) : 0)
       + (value.bar != null ? ProtoAdapter.STRING.encodedSizeWithTag(2, value.bar) : 0)
       + (value.baz != null ? Nested.ADAPTER.encodedSizeWithTag(3, value.baz) : 0)
       + (value.qux != null ? ProtoAdapter.UINT64.encodedSizeWithTag(4, value.qux) : 0)
       + ProtoAdapter.FLOAT.asRepeated().encodedSizeWithTag(5, value.fred)
       + (value.daisy != null ? ProtoAdapter.DOUBLE.encodedSizeWithTag(6, value.daisy) : 0)
       + FooBar.ADAPTER.asRepeated().encodedSizeWithTag(7, value.nested)
       + (value.ext != null ? FooBarBazEnum.ADAPTER.encodedSizeWithTag(101, value.ext) : 0)
       + FooBarBazEnum.ADAPTER.asRepeated().encodedSizeWithTag(102, value.rep)
       + value.unknownFields().size();
 }
예제 #5
0
파일: FooBar.java 프로젝트: pforhan/wire
 @Override
 public void encode(ProtoWriter writer, FooBar value) throws IOException {
   if (value.foo != null) ProtoAdapter.INT32.encodeWithTag(writer, 1, value.foo);
   if (value.bar != null) ProtoAdapter.STRING.encodeWithTag(writer, 2, value.bar);
   if (value.baz != null) Nested.ADAPTER.encodeWithTag(writer, 3, value.baz);
   if (value.qux != null) ProtoAdapter.UINT64.encodeWithTag(writer, 4, value.qux);
   if (value.fred != null) ProtoAdapter.FLOAT.asRepeated().encodeWithTag(writer, 5, value.fred);
   if (value.daisy != null) ProtoAdapter.DOUBLE.encodeWithTag(writer, 6, value.daisy);
   if (value.nested != null) FooBar.ADAPTER.asRepeated().encodeWithTag(writer, 7, value.nested);
   if (value.ext != null) FooBarBazEnum.ADAPTER.encodeWithTag(writer, 101, value.ext);
   if (value.rep != null)
     FooBarBazEnum.ADAPTER.asRepeated().encodeWithTag(writer, 102, value.rep);
   writer.writeBytes(value.unknownFields());
 }