@Override public int encodedSize(DescriptorProto value) { return (value.name != null ? ProtoAdapter.STRING.encodedSize(1, value.name) : 0) + (value.doc != null ? ProtoAdapter.STRING.encodedSize(8, value.doc) : 0) + FieldDescriptorProto.ADAPTER.asRepeated().encodedSize(2, value.field) + FieldDescriptorProto.ADAPTER.asRepeated().encodedSize(6, value.extension) + DescriptorProto.ADAPTER.asRepeated().encodedSize(3, value.nested_type) + EnumDescriptorProto.ADAPTER.asRepeated().encodedSize(4, value.enum_type) + ExtensionRange.ADAPTER.asRepeated().encodedSize(5, value.extension_range) + (value.options != null ? MessageOptions.ADAPTER.encodedSize(7, value.options) : 0) + value.unknownFields().size(); }
@Override public void encode(ProtoWriter writer, DescriptorProto value) throws IOException { if (value.name != null) ProtoAdapter.STRING.encodeTagged(writer, 1, value.name); if (value.doc != null) ProtoAdapter.STRING.encodeTagged(writer, 8, value.doc); if (value.field != null) FieldDescriptorProto.ADAPTER.asRepeated().encodeTagged(writer, 2, value.field); if (value.extension != null) FieldDescriptorProto.ADAPTER.asRepeated().encodeTagged(writer, 6, value.extension); if (value.nested_type != null) DescriptorProto.ADAPTER.asRepeated().encodeTagged(writer, 3, value.nested_type); if (value.enum_type != null) EnumDescriptorProto.ADAPTER.asRepeated().encodeTagged(writer, 4, value.enum_type); if (value.extension_range != null) ExtensionRange.ADAPTER.asRepeated().encodeTagged(writer, 5, value.extension_range); if (value.options != null) MessageOptions.ADAPTER.encodeTagged(writer, 7, value.options); writer.writeBytes(value.unknownFields()); }
@Override public DescriptorProto 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.name(ProtoAdapter.STRING.decode(reader)); break; case 8: builder.doc(ProtoAdapter.STRING.decode(reader)); break; case 2: builder.field.add(FieldDescriptorProto.ADAPTER.decode(reader)); break; case 6: builder.extension.add(FieldDescriptorProto.ADAPTER.decode(reader)); break; case 3: builder.nested_type.add(DescriptorProto.ADAPTER.decode(reader)); break; case 4: builder.enum_type.add(EnumDescriptorProto.ADAPTER.decode(reader)); break; case 5: builder.extension_range.add(ExtensionRange.ADAPTER.decode(reader)); break; case 7: builder.options(MessageOptions.ADAPTER.decode(reader)); break; default: { FieldEncoding fieldEncoding = reader.peekFieldEncoding(); Object value = fieldEncoding.rawProtoAdapter().decode(reader); builder.addUnknownField(tag, fieldEncoding, value); } } } reader.endMessage(token); return builder.build(); }