Compile Protocol Buffers

Distributed Services with Go — by Travis Jeffery (20 / 84)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Define Your Domain Types as Protocol Buffers | TOC | Work with the Generated Code 👉

To compile protobuf into the code of some programming language, you need the runtime for that language. The compiler itself doesn’t know how to compile protobuf into every language — it needs a language-specific runtime to do so.

Go has two runtimes to compile protobuf into Go code. The Go team and the protobuf team at Google developed the original runtime.[6] Then a team of folks who wanted more features forked the original runtime and developed it into gogoprotobuf, with more code-generation features and faster marshaling and unmarshaling. Projects like Etcd, Mesos, Kubernetes, Docker, CockroachDB, and NATS as well as companies like Dropbox and Sendgrid used gogoprotobuf. I used gogoprotobuf for my projects to integrate with Kubernetes’ protocol buffers and for gogoprotobuf’s features.

In March 2020, the Go team released a major revision of the Go API (APIv2)[7] for protocol buffers with improved performance[8] and a reflection API that enables adding features like those provided by gogoprotobuf. Projects[9] that used gogoprotobuf have begun switching to APIv2[10] because of APIv2’s improved performance, its new reflection API, its incompatibility with gogoprotobuf, and the gogoprotobuf project needing new ownership.[11] I recommend using APIv2, too.

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.