コード例 #1
0
ファイル: FooBar.java プロジェクト: pforhan/wire
 @Override
 public FooBar decode(ProtoReader reader) throws IOException {
   Builder builder = new Builder();
   long token = reader.beginMessage();
   for (int tag; (tag = reader.nextTag()) != -1; ) {
     switch (tag) {
       case 1:
         builder.foo(ProtoAdapter.INT32.decode(reader));
         break;
       case 2:
         builder.bar(ProtoAdapter.STRING.decode(reader));
         break;
       case 3:
         builder.baz(Nested.ADAPTER.decode(reader));
         break;
       case 4:
         builder.qux(ProtoAdapter.UINT64.decode(reader));
         break;
       case 5:
         builder.fred.add(ProtoAdapter.FLOAT.decode(reader));
         break;
       case 6:
         builder.daisy(ProtoAdapter.DOUBLE.decode(reader));
         break;
       case 7:
         builder.nested.add(FooBar.ADAPTER.decode(reader));
         break;
       case 101:
         {
           try {
             builder.ext(FooBarBazEnum.ADAPTER.decode(reader));
           } catch (ProtoAdapter.EnumConstantNotFoundException e) {
             builder.addUnknownField(tag, FieldEncoding.VARINT, (long) e.value);
           }
           break;
         }
       case 102:
         {
           try {
             builder.rep.add(FooBarBazEnum.ADAPTER.decode(reader));
           } catch (ProtoAdapter.EnumConstantNotFoundException e) {
             builder.addUnknownField(tag, FieldEncoding.VARINT, (long) e.value);
           }
           break;
         }
       default:
         {
           FieldEncoding fieldEncoding = reader.peekFieldEncoding();
           Object value = fieldEncoding.rawProtoAdapter().decode(reader);
           builder.addUnknownField(tag, fieldEncoding, value);
         }
     }
   }
   reader.endMessage(token);
   return builder.build();
 }
コード例 #2
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();
 }
コード例 #3
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());
 }