Home > Blockchain >  Difference between a DynamicMessage and a typed Message
Difference between a DynamicMessage and a typed Message

Time:06-14

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?

CodePudding user response:

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.

  • Related