6

Im using protobuf 2.6.1 and I have a case where there are complex types such as UUID represented as two fixed64 fields, timestamps represented as longs etc which need to be printed in a more human readable way.

Im looking for extending the toString for all protobufs generically to convert the complex types to human readable types.

Is there such a way possible? If there isnt one for 2.6.1, is there any option in >= 3.0 ?

aks
  • 61
  • 2
  • 3 allows you to output json which you could re-parse and customize maybe, but I'm not aware of toString customization. It's just not meant to be a nicely displayed thing. You can also put your own utility `String toString(Message input)` method with some code like `if (input instanceof SpecialMessage) return doThefancyDisplay(input) else return input.toString()` to customize where you need it – zapl Aug 14 '18 at 19:55
  • You can't do this without just writing your own method to convert the proto to a string. If you could change the behaviour of protos directly, it would break other code which relies upon the default format. – Andy Turner Aug 14 '18 at 20:00
  • If you're just looking for some shorter output, you can use `TextFormat.shortDebugString(msg)` instead of `msg.toString()` – cfstras Jan 21 '21 at 18:02

0 Answers0