Skip to content
Advertisement

Difference between a DynamicMessage and a typed Message

I’m trying to understand more about protobuf DynamicMessage. If I have a message Animal that is coming from an input stream, code that has the Animal protoc java type (say AnimalProto) will use that type directly to deserialize. Whereas a code without the compile time dependency on AnimalProto but has access to the Type descriptor will use that Type descriptor to deserialize from the input stream into a DynamicMessage object.

What is the difference between the deserialized AnimalProto object and the DynamcicMessage object? As far as the jvm is concerned .equals() will obviously return false. Are their serialized formats the same, i.e. if I were to send them over the wire again, the format would be the same regardless of which method it was constructed using?

Advertisement

Answer

Yes, their serialized formats will remain the same.

The AnimalProto object simply has the AnimalProto API — you can get its fields by name, for example.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement