mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2024-12-28 00:19:55 +00:00
2ce1ca9e3f
Port message formatting logic in testing/protocmp to internal/msgfmt and improve upon its output. This formatter is optimized for humanly readable output. It takes the best parts of both the JSON and proto text formats. The good of prototext: * It supports emitting unknown fields (useful for debugging). * It is relatively concise in the common-case since keys do not need to be represented as quoted strings (e.g., "key" vs key). The bad of prototext: * Requires relatively large dependency on encoding/prototext. * Our implementation lacks support for serializing packed lists. * Lacks support for readable maps. * Lacks support for readable Timestamp and Duration. The good of protojson: * First-class support for readable maps. * First-class support for readable Timestamp and Duration. The bad of protojson: * Requires relatively large dependency on encoding/protojson. * Lacks support for emitting unknown fields. * More verbose in the common-case as keys are quoted strings. The msgfmt package has the benefits of both protojson and prototext, but none of the detriments. It is a relatively simple implementation. This output is only intended for human consumption with no associated deserialization implementation. To avoid any illusion that this is identical to either the proto text or JSON formats, this always emits surrounding "{}" for top-level messages and the keys are not quoted strings. This CL does not use this format for generated Message.String methods as there is concerns about being inconsistent with the String methods as implemented in other languages. Having it be a seperate package makes it trivial to switch over to this if desired. Change-Id: I8b3581904d1624e84bf1b1954d2f01e5774b7f87 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/223752 Reviewed-by: Damien Neil <dneil@google.com> |
||
---|---|---|
.. | ||
protocmp | ||
protopack | ||
prototest |