Define the EmptyMessage
type as:
message EmptyMessage {
Now EmptyMessage
your message as EmptyMessage
, then call toString()
on it.
Why does it work? Well, keep in mind that it is backward compatible to add fields to the message type. When you add a field, then send a message, using this field, to an old program that was not built with knowledge of the field, then the field is considered as an "unknown field". Unknown fields are printed as number / value pairs. Now, if you start with EmptyMessage
and add fields, you can get any other message. Therefore, all message types are "backward compatible" with EmptyMessage
. Therefore, any message can be parsed as an EmptyMessage
to process all fields as unknown fields.
source share