百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

protobuf

> 编程语言
开源

[已过时] 适用于 Go 的协议缓冲区与 Gadgets

5.7K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

[已过时] 适用于 Go 的协议缓冲区与 Gadgets

GoGo Protobuf is Deprecated

[Deprecated] Protocol Buffers for Go with Gadgets

gogoprotobuf is a fork of golang/protobuf with extra code generation features.

This code generation is used to achieve:

  • fast marshalling and unmarshalling
  • more canonical Go structures
  • goprotobuf compatibility
  • less typing by optionally generating extra helper code
  • peace of mind by optionally generating test and benchmark code
  • other serialization formats

Keeping track of how up to date gogoprotobuf is relative to golang/protobuf is done in this issue

Release v1.3.0

The project has updated to release v1.3.0. Check out the release notes here.

With this new release comes a new internal library version. This means any newly generated *pb.go files generated with the v1.3.0 library will not be compatible with the old library version (v1.2.1). However, current *pb.go files (generated with v1.2.1) should still work with the new library.

Please make sure you manage your dependencies correctly when upgrading your project. If you are still using v1.2.1 and you update your dependencies, one of which could include a new *pb.go (generated with v1.3.0), you could get a compile time error.

Our upstream repo, golang/protobuf, also had to go through this process in order to update their library version. Here is a link explaining hermetic builds.

Users

These projects use gogoprotobuf:

  • etcd - blog - sample proto file
  • spacemonkey - blog
  • badoo - sample proto file
  • mesos-go - sample proto file
  • heka - the switch from golang/protobuf to gogo/protobuf when it was still on code.google.com
  • cockroachdb - sample proto file
  • go-ipfs - sample proto file
  • rkive-go - sample proto file
  • dropbox
  • srclib - sample proto file
  • adyoulike
  • cloudfoundry - sample proto file
  • kubernetes - go2idl built on top of gogoprotobuf
  • dgraph - release notes - benchmarks
  • centrifugo - release notes - blog
  • docker swarmkit - sample proto file
  • nats.io - go-nats-streaming
  • tidb - Communication between tidb and tikv
  • protoactor-go - vanity command that also generates actors from service definitions
  • containerd - vanity command with custom field names that conforms to the golang convention.
  • nakama
  • proteus
  • carbonzipper stack
  • sendgrid
  • zero-os/0-stor
  • go-spacemesh
  • cortex - sample proto file
  • Apache SkyWalking APM - Istio telemetry receiver based on Mixer bypass protocol
  • Hyperledger Burrow - a permissioned DLT framework
  • IOV Weave - a blockchain framework - sample proto files

Please let us know if you are using gogoprotobuf by posting on our GoogleGroup.

Mentioned

  • Cloudflare - go serialization talk - Albert Strasheim
  • GopherCon 2014 Writing High Performance Databases in Go by Ben Johnson
  • alecthomas' go serialization benchmarks
  • Go faster with gogoproto - Agniva De Sarker
  • Evolution of protobuf (Gource Visualization) - Landon Wilkins
  • Creating GopherJS Apps with gRPC-Web - Johan Brandhorst
  • So you want to use GoGo Protobuf - Johan Brandhorst
  • Advanced gRPC Error Usage - Johan Brandhorst
  • gRPC Golang Course on Udemy - Stephane Maarek

Preparing for GopherCon UK 2022

Getting Started

There are several ways to use gogoprotobuf, but for all you need to install go and protoc. After that you can choose:

  • Speed
  • More Speed and more generated code
  • Most Speed and most customization

Installation

To install it, you must first have Go (at least version 1.6.3 or 1.9 if you are using gRPC) installed (see http://golang.org/doc/install). Latest patch versions of 1.12 and 1.15 are continuously tested.

Next, install the standard protocol buffer implementation from https://github.com/google/protobuf. Most versions from 2.3.1 should not give any problems, but 2.6.1, 3.0.2 and 3.14.0 are continuously tested.

Speed

Install the protoc-gen-gofast binary

go get github.com/gogo/protobuf/protoc-gen-gofast

Use it to generate faster marshaling and unmarshaling go code for your protocol buffers.

protoc --gofast_out=. myproto.proto

This does not allow you to use any of the other gogoprotobuf extensions.

More Speed and more generated code

Fields without pointers cause less time in the garbage collector. More code generation results in more convenient methods.

Other binaries are also included:

protoc-gen-gogofast (same as gofast, but imports gogoprotobuf)
protoc-gen-gogofaster (same as gogofast, without XXX_unrecognized, less pointer fields)
protoc-gen-gogoslick (same as gogofaster, but with generated string, gostring and equal methods)

Installing any of these binaries is easy. Simply run:

go get github.com/gogo/protobuf/proto
go get github.com/gogo/protobuf/{binary}
go get github.com/gogo/protobuf/gogoproto

These binaries allow you to use gogoprotobuf extensions. You can also use your own binary.

To generate the code, you also need to set the include path properly.

protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/gogo/protobuf/protobuf --{binary}_out=. myproto.proto

To use proto files from "google/protobuf" you need to add additional args to protoc.

protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/gogo/protobuf/protobuf --{binary}_out=\
Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types:. \
myproto.proto

Note that in the protoc command, {binary} does not contain the initial prefix of "protoc-gen".

Most Speed and most customization

Customizing the fields of the messages to be the fields that you actually want to use removes the need to copy between the structs you use and structs you use to serialize. gogoprotobuf also offers more serialization formats and generation of tests and even more methods.

Please visit the extensions page for more documentation.

Install protoc-gen-gogo:

go get github.com/gogo/protobuf/proto
go get github.com/gogo/protobuf/jsonpb
go get github.com/gogo/protobuf/protoc-gen-gogo
go get github.com/gogo/protobuf/gogoproto

GRPC

It works the same as golang/protobuf, simply specify the plugin. Here is an example using gofast:

protoc --gofast_out=plugins=grpc:. my.proto

See https://github.com/gogo/grpc-example for an example of using gRPC with gogoprotobuf and the wider grpc-ecosystem.

License

GitHub Issues· 0 开放

在 GitHub 查看全部

暂无开放 Issues,或尚未同步最近议题。

核心特点

  • •fast marshalling and unmarshalling
  • •more canonical Go structures
  • •goprotobuf compatibility
  • •less typing by optionally generating extra helper code
  • •peace of mind by optionally generating test and benchmark code
  • •other serialization formats
  • •<a href="https://www.spacemonkey.com/">spacemonkey</a> - <a href="https://www.spacemonkey.com/blog/posts/go-space-monkey">blog</a>
  • •<a href="http://badoo.com">badoo</a> - <a href="https://github.com/badoo/lsd/blob/32061f501c5eca9c76c596d790b450501ba27b2f/proto/lsd.proto">sample proto file</a>
  • •<a href="https://www.dropbox.com">dropbox</a>
  • •<a href="https://srclib.org/">srclib</a> - <a href="https://github.com/sourcegraph/srclib/blob/6538858f0c410cac5c63440317b8d009e889d3fb/graph/def.proto">sample proto file</a>

> 标签

Gogogolanggrpcprotobuf

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言