Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protobuf string to readable string?

I am using protobuf in a Client Server WCF solution and I need to log the content of the message(parameters) to file as efficiant as possible(avoiding heavy serializing and de-serializing).

In the IClientMessageInspector I get the message in raw but in most of the messages there is a Protobuf string that is unreadable. Even if I base64decode it, it would probably still be unreadable. So is there a easy and efficiant way to translate this profostring into something readable that I can log to file?

Regards

like image 215
Banshee Avatar asked Oct 24 '25 22:10

Banshee


1 Answers

You cannot create a meaningful and accurate text representation of an arbitrary protobuf payload, because the binary encoding itself is ambiguous and overloaded - the exact same binary can mean many different things depending on the schema being used (the schema is implicit from the type model, in the case of protobuf-net, from the tags in the question).

If you know the schema/type, your best bet would be to deserialize the protobuf payload into the type, and then run that type through your preferred json / xml / yaml / csv / whatever serializer, and log that.

If you just need to record the bytes for audit purposes: base-64 should suffice, but again: it will be meaningless without context.

like image 84
Marc Gravell Avatar answered Oct 27 '25 12:10

Marc Gravell