示例#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 Nested decode(ProtoReader reader) throws IOException {
   Builder builder = new Builder();
   long token = reader.beginMessage();
   for (int tag; (tag = reader.nextTag()) != -1; ) {
     switch (tag) {
       case 1:
         {
           try {
             builder.value(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();
 }