binbin846
binbin846

Reputation: 35

Read Protobuf data without schema

One is the original data, the other is the data converted by the web analyzer. How can I convert the data into the web analyzer with C#? I don't have a model.

enter image description here enter image description here

Upvotes: 2

Views: 2848

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1064204

If you don't have a schema, frankly you need to reverse engineer one. Or chase down the source of the data and obtain the existing one, which is usually much easier.

Protobuf is an ambiguous format without it, and there is no one correct single way if decoding many of the "wire types". You can use tools like protoc (in decode-raw mode), or https://protogen.marcgravell.com/decode to try and decipher the raw data to try and put a schema together, but it is a little tedious and often requires some knowledge of what the data should be. For example, a "variant" - after the varint step - could be:

  • an enum
  • a twos-complement signed integer
  • a twos-complement unsigned integer
  • a zig-zag signed integer

Plus for the last 3 options, the same payload could be 32-bit or 64-bit (this doesn't change the value, but may change things if a later value is larger).

If you need help, I might be able to take a look - I've reverse engineered protobuf schemas many times.


If you just want raw access to the interpreted stream, protobuf-net has a ProtoReader type that works broadly like XmlReader etc, and may help you. But all of the ambiguities described above will remain.

Upvotes: 4

Related Questions