cmd/protoc-gen-json contains a protoc compiler plugin for generating JSON dumps of protoc plugin generation requests, i.e. the literal request to the protoc-gen-json command from protoc.
As it is literally the JSON form of plugin.CodeGeneratorRequest, it can be unmarshaled into the same exact structure which is useful for writing tests without invoking protoc directly (and attemping to detect plugin failure through the compiler proxy).
First install Go and Protobuf itself, then install the plugin using go get:
go get -u sourcegraph.com/sourcegraph/prototools/cmd/protoc-gen-jsonSimply invoke protoc with the --json_out command-line parameter:
protoc --json_out="<OUT_DIR>" input.proto
protoc --json_out="<OPTIONS>:<OUT_DIR>" input.protoWhere <OPTIONS> is a comma-seperated list of key=value,key2=value2 options (which are listed in detail below). For example:
protoc --json_out="dump/" a.proto b.protoWould produce a JSON dump file (out.json) for both a.proto and b.proto inside the dump/ directory.
| Option | Default | Description |
|---|---|---|
out |
out.json |
Output file name (not directory). |
indent |
(two spaces) |
Indention string to use for each nested JSON element. |
If you run into trouble or have questions, please open an issue.