by MathMonkeyMan · 2y ago · 0 comments
Here's another approach. The AST of a .proto file is itself a protobuf. That's how the codegen plugins work. Protobuf also has a canonical mapping to JSON, so...
What you can do is use protoc to parse the .proto file, spit it out as JSON, and then process that data using your favorite pattern matching language. I wrote a [tool][1] that helps with that. For example, here's some [js code][2] that translates protobuf message definitions into "types" for use in an ORM.
[1]: https://github.com/dgoffredo/protojson
[2]: https://github.com/dgoffredo/okra/blob/master/lib/proto2type...
https://github.com/metaverse/truss/blame/master/svcdef/svcde...
Wouldn't it have been far more efficient to contribute back to protoc? Certainly posting a patch to a parser takes far fewer work than writing an alternative implementation of the same parser.
In fact, that's the whole premise of GitHub: you fork a repo, you work on a feature branch, you post a PR, anf your fork stays there.
To repeat my point: it's easier to add small features to a parser than it is to reimplement everything, and posting a PR with your small change takes no work at all.
- learning a new language
- learning a new codebase
- modifying that codebase
- distributing a that modified fork of a project in c++ alongside what I was building in Go
It was much easier in my case to build it as a small part of the tool I was already building and move on with my life.
Also, this reads like they might not have seen the newer proto3 optional keyword, or know about the well-known wrapper types.