It sounds like you're working in Java.
In Java you need to create, setup, and then provide an
ExtensionRegistry
1) The way you do this is you create a new one...
final ExtensionRegistry extensionRegistry =
ExtensionRegistry.newInstance();
2) then register any extensions you have by calling the appropriate
compiled proto FILE classes'
"registerAllExtensions(ExtensionRegistry)" method as such...
MyProtoFile.registerAllExtensions(extensionRegistry);
Tip: the name of this class is determined by the name of your proto
file or the "java_outer_classname" file option.
3) Then you can parse messages with this ExtensionRegistry via...
MyMessage.parse(bytes, extensionRegistry);
You probably want to create the extension registry once and then save
it for use during all parsing. You will likely need to register
multiple files worth of extension (depends on how you use extensions)
in which case simply repeat step 2 for each file using the same
ExtensionRegistry instance - all the extensions must be registered to
the same registry.
On Oct 11, 12:43 pm, prem <mpremj...@gmail.com> wrote:
> On one machine, serialized a Message2, which has been extended from
> Message1.
> The parameters in Mesage2 were set using setExtension API. Did
> writeDelimitedTo to write to a byte outpurstream.
> Then ran protoc --include_imports --descriptor_set_out=message2.desc --
> java_out=message2.proto
> On the other machine:
> Got the .desc file here, create a inputstream from it.
> DescriptorProtos.FileDescriptorSet fileDescriptorSet =
> DescriptorProtos.FileDescriptorSet.parseFrom(inputStream);
> Created a descripter map and created the dynamic message:
> DynamicMessage dynamicMessage = DynamicMessage.parseFrom(descriptor,
> message);
> when trying to print
> System.out.println(" allFields.size =
> "+dynamicMessage.getAllFields().size()); System.out.println("
> unknownFields.tostring = "+dynamicMessage.getUnknownFields());
> The fields in the Message2 are coming as the unknown fields, tried to
> provide the extension registry, but not sure how to do that.
> How can we dynamically parse the names and values of the fields in the
> extended message2, with the .desc file. or is there other way to do
> this?