简体   繁体   English

显示协议缓冲区消息中的所有元素

[英]Show all elements 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 into an XML message and then show it? 我需要使用反射还是将消息转换为XML消息然后显示? Ideally some generic code that will work for any message. 理想情况下,一些适用于任何消息的通用代码。 Lars 拉尔斯

A protobuf message is internally ambiguous unless you have the .proto schema (or can infer a schema) available, as (for example) a "string" wire-type could represent: 除非您具有.proto模式(或可以推断模式),否则protobuf消息在内部是模棱两可的,例如(例如)“字符串”线型可以表示:

  • a utf-8 string utf-8字符串
  • a BLOB BLOB
  • a sub-message 子消息
  • a packed array 打包数组

Similar ambiguity exists for all wire-types (except perhaps "groups"). 所有导线类型(也许“组”除外)都存在类似的歧义。

My recommendation would be to run it through your existing deserialization process (against the type-model that you presumably have available in the project) to get an object model suitable for inspection. 我的建议是通过现有的反序列化过程(针对您可能在项目中使用的类型模型)运行它,以获得适合检查的对象模型。 From the object-model you have all the usual options - reflection, serialization via XmlSerializer / JavaScriptSerializer , etc. 在对象模型中,您可以使用所有通常的选项-反射,通过XmlSerializer / JavaScriptSerializer序列化等。

If all you have is the raw data, there is a wireshark plugin that might help, or protobuf-net exists a ProtoReader class that might be useful for parsing such a stream; 如果您只拥有原始数据,那么可以使用一个Wireshark插件来提供帮助,或者protobuf-net存在一个ProtoReader类,该类可能对解析此类流很有用。 but the emphasis here is that the stream is tricky to decipher in isolation. 但是这里强调的是,流很难被孤立地解密。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM