Show all items in a protocol buffer message

How can I show all elements in a protocol buffer message? Do I need to use reflection or convert the message to an XML message and then show it? Ideally, some kind of generic code that will work for any message. Lars

+1
source share
1 answer

The protobuf message is internally ambiguous unless you have a .proto schema (or can output a schema), because (for example) a wired string type can represent:

  • utf-8 string
  • Blob
  • sub-message
  • packed array

A similar ambiguity exists for all types of conductors (except, possibly, β€œgroups”).

My recommendation would be to run it through the existing deserialization process (compared to the type model you supposedly got in the project) to get an object model suitable for validation. From the object model, you have all the usual options - reflection, serialization via XmlSerializer / JavaScriptSerializer , etc.

If all you have is raw data, there is a plughar plugin that can help, or protobuf-net there is a ProtoReader class that can be useful for parsing such a stream; but here the focus is on the fact that the flow is difficult to describe in isolation.

+1
source

Source: https://habr.com/ru/post/1393127/


All Articles