DynamicProtoCoder extends ProtoCoder<DynamicMessage> { public static DynamicProtoCoder of(Descriptors.Descriptor protoMessageDescriptor) { return new DynamicProtoCoder( ProtoDomain.buildFrom(protoMessageDescriptor), protoMessageDescriptor.getFullName(), ImmutableSet.of()); } private  DynamicProtoCoder(
      ProtoDomain domain, String messageName, Set<Class<?>> extensionHostClasses); static DynamicProtoCoder of(Descriptors.Descriptor protoMessageDescriptor); static DynamicProtoCoder of(
      ProtoDomain domain, Descriptors.Descriptor protoMessageDescriptor); static DynamicProtoCoder of(ProtoDomain domain, String messageName); @Override DynamicProtoCoder withExtensionsFrom(Iterable<Class<?>> moreExtensionHosts); @Override boolean equals(@Nullable Object other); @Override int hashCode(); static CoderProvider getCoderProvider(); static final long serialVersionUID; }
@Test public void testDynamicMessage() throws Exception { DynamicMessage message = DynamicMessage.newBuilder(MessageA.getDescriptor()) .setField( MessageA.getDescriptor().findFieldByNumber(MessageA.FIELD1_FIELD_NUMBER), "foo") .build(); Coder<DynamicMessage> coder = DynamicProtoCoder.of(message.getDescriptorForType()); for (Coder.Context context : ALL_CONTEXTS) { CoderProperties.coderDecodeEncodeInContext( coder, context, message, IsDynamicMessageEqual.equalTo(message)); } }
@Test public void testDynamicNestedRepeatedMessage() throws Exception { DynamicMessage message = DynamicMessage.newBuilder(MessageA.getDescriptor()) .setField( MessageA.getDescriptor().findFieldByNumber(MessageA.FIELD1_FIELD_NUMBER), "foo") .addRepeatedField( MessageA.getDescriptor().findFieldByNumber(MessageA.FIELD2_FIELD_NUMBER), DynamicMessage.newBuilder(MessageB.getDescriptor()) .setField( MessageB.getDescriptor().findFieldByNumber(MessageB.FIELD1_FIELD_NUMBER), true) .build()) .addRepeatedField( MessageA.getDescriptor().findFieldByNumber(MessageA.FIELD2_FIELD_NUMBER), DynamicMessage.newBuilder(MessageB.getDescriptor()) .setField( MessageB.getDescriptor().findFieldByNumber(MessageB.FIELD1_FIELD_NUMBER), false) .build()) .build(); Coder<DynamicMessage> coder = DynamicProtoCoder.of(message.getDescriptorForType()); for (Coder.Context context : ALL_CONTEXTS) { CoderProperties.coderDecodeEncodeInContext( coder, context, message, IsDynamicMessageEqual.equalTo(message)); } }