Custom printers for protobuf in Java
Asked Answered
C

0

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 ?

Cyclopentane answered 14/8, 2018 at 19:47 Comment(3)
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 itChert
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.Riba
If you're just looking for some shorter output, you can use TextFormat.shortDebugString(msg) instead of msg.toString()Charlacharlady

© 2022 - 2024 — McMap. All rights reserved.