[GoGo Protobuf looking for new ownership](https://github.com/gogo/protobuf/issues/691)

# Protocol Buffers for Go with Gadgets

[![Build Status](https://github.com/gogo/protobuf/workflows/Continuous%20Integration/badge.svg)](https://github.com/gogo/protobuf/actions)
[![GoDoc](https://godoc.org/github.com/gogo/protobuf?status.svg)](http://godoc.org/github.com/gogo/protobuf)

gogoprotobuf is a fork of golang/protobuf (https://github.com/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 (https://github.com/gogo/protobuf/issues/191)

## Release v1.3.0

The project has updated to release v1.3.0. Check out the release notes here (https://github.com/gogo/protobuf/releases/tag/v1.3.0).

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 (https://github.com/golang/protobuf/issues/763#issuecomment-442434870).

## Users

These projects use gogoprotobuf:

  - etcd (http://godoc.org/github.com/coreos/etcd) - blog (https://blog.gopheracademy.com/advent-2015/etcd-distributed-key-value-store-with-grpc-http2/) - sample proto file (https://github.com/coreos/etcd/blob/master/etcdserver/etcdserverpb/etcdserver.proto)
  - spacemonkey (https://www.spacemonkey.com/) - blog (https://www.spacemonkey.com/blog/posts/go-space-monkey)
  - badoo (http://badoo.com) - sample proto file (https://github.com/badoo/lsd/blob/32061f501c5eca9c76c596d790b450501ba27b2f/proto/lsd.proto)
  - mesos-go (https://github.com/mesos/mesos-go) - sample proto file (https://github.com/mesos/mesos-go/blob/f9e5fb7c2f50ab5f23299f26b6b07c5d6afdd252/api/v0/mesosproto/authentication.proto)
  - heka (https://github.com/mozilla-services/heka) - the switch from golang/protobuf to gogo/protobuf when it was still on code.google.com (https://github.com/mozilla-services/heka/commit/eb72fbf7d2d28249fbaf8d8dc6607f4eb6f03351)
  - cockroachdb (https://github.com/cockroachdb/cockroach) - sample proto file (https://github.com/cockroachdb/cockroach/blob/651d54d393e391a30154e9117ab4b18d9ee6d845/roachpb/metadata.proto)
  - go-ipfs (https://github.com/jbenet/go-ipfs) - sample proto file (https://github.com/ipfs/go-ipfs/blob/2b6da0c024f28abeb16947fb452787196a6b56a2/merkledag/pb/merkledag.proto)
  - rkive-go (https://github.com/philhofer/rkive) - sample proto file (https://github.com/philhofer/rkive/blob/e5dd884d3ea07b341321073882ae28aa16dd11be/rpbc/riak_dt.proto)
  - dropbox (https://www.dropbox.com)
  - srclib (https://srclib.org/) - sample proto file (https://github.com/sourcegraph/srclib/blob/6538858f0c410cac5c63440317b8d009e889d3fb/graph/def.proto)
  - adyoulike (http://www.adyoulike.com/)
  - cloudfoundry (http://www.cloudfoundry.org/) - sample proto file (https://github.com/cloudfoundry/bbs/blob/d673710b8c4211037805129944ee4c5373d6588a/models/events.proto)
  - kubernetes (http://kubernetes.io/) - go2idl built on top of gogoprotobuf (https://github.com/kubernetes/kubernetes/tree/88d8628137f94ee816aaa6606ae8cd045dee0bff/cmd/libs/go2idl)
  - dgraph (https://dgraph.io/) - release notes (https://github.com/dgraph-io/dgraph/releases/tag/v0.4.3) - benchmarks (https://discuss.dgraph.io/t/gogoprotobuf-is-extremely-fast/639)
  - centrifugo (https://github.com/centrifugal/centrifugo) - release notes (https://forum.golangbridge.org/t/centrifugo-real-time-messaging-websocket-or-sockjs-server-v1-5-0-released/2861) - blog (https://medium.com/@fzambia/centrifugo-protobuf-inside-json-outside-21d39bdabd68#.o3icmgjqd)
  - docker swarmkit (https://github.com/docker/swarmkit) - sample proto file (https://github.com/docker/swarmkit/blob/63600e01af3b8da2a0ed1c9fa6e1ae4299d75edb/api/objects.proto)
  - nats.io (https://nats.io/) - go-nats-streaming (https://github.com/nats-io/go-nats-streaming/blob/master/pb/protocol.proto)
  - tidb (https://github.com/pingcap/tidb) - Communication between tidb (https://github.com/pingcap/tipb/blob/master/generate-go.sh#L4) and tikv (https://github.com/pingcap/kvproto/blob/master/generate_go.sh#L3)
  - protoactor-go (https://github.com/AsynkronIT/protoactor-go) - vanity command (https://github.com/AsynkronIT/protoactor-go/blob/master/protobuf/protoc-gen-protoactor/main.go) that also generates actors from service definitions
  - containerd (https://containerd.io/) - vanity command with custom field names (https://github.com/containerd/containerd/tree/master/cmd/protoc-gen-gogoctrd) that conforms to the golang convention.
  - nakama (https://github.com/heroiclabs/nakama)
  - proteus (https://github.com/src-d/proteus)
  - carbonzipper stack (https://github.com/go-graphite)
  - sendgrid (https://sendgrid.com/)
  - zero-os/0-stor (https://github.com/zero-os/0-stor)
  - go-spacemesh (https://github.com/spacemeshos/go-spacemesh)
  - cortex (https://github.com/weaveworks/cortex) - sample proto file (https://github.com/weaveworks/cortex/blob/fee02a59729d3771ef888f7bf0fd050e1197c56e/pkg/ingester/client/cortex.proto)
  - Apache SkyWalking APM (http://skywalking.apache.org/) - Istio telemetry receiver based on Mixer bypass protocol
  - Hyperledger Burrow (https://github.com/hyperledger/burrow) - a permissioned DLT framework
  - IOV Weave (https://github.com/iov-one/weave) - a blockchain framework - sample proto files (https://github.com/iov-one/weave/tree/23f9856f1e316f93cb3d45d92c4c6a0c4810f6bf/spec/gogo)

Please let us know if you are using gogoprotobuf by posting on our GoogleGroup (https://groups.google.com/forum/#!topic/gogoprotobuf/Brw76BxmFpQ).

### Mentioned

  - Cloudflare - go serialization talk - Albert Strasheim (http://www.slideshare.net/albertstrasheim/serialization-in-go)
  - GopherCon 2014 Writing High Performance Databases in Go by Ben Johnson (https://youtu.be/4xB46Xl9O9Q?t=557)
  - alecthomas' go serialization benchmarks (https://github.com/alecthomas/go_serialization_benchmarks)
  - Go faster with gogoproto - Agniva De Sarker (http://agniva.me/go/2017/11/18/gogoproto.html)
  - Evolution of protobuf (Gource Visualization) - Landon Wilkins (https://www.youtube.com/watch?v=CY9T020HLP8)
  - Creating GopherJS Apps with gRPC-Web - Johan Brandhorst (https://fosdem.org/2018/schedule/event/gopherjs/)
  - So you want to use GoGo Protobuf - Johan Brandhorst (https://jbrandhorst.com/post/gogoproto/)
  - Advanced gRPC Error Usage - Johan Brandhorst (https://jbrandhorst.com/post/grpc-errors/)
  - gRPC Golang Course on Udemy - Stephane Maarek (https://www.udemy.com/grpc-golang/?couponCode=GITHUB10)

## 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](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](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](https://github.com/gogo/protobuf/blob/master/extensions.md).

### 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](https://github.com/gogo/protobuf/blob/master/extensions.md). 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](https://github.com/gogo/protobuf/blob/master/extensions.md) 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](https://github.com/gogo/grpc-example) for an example of using gRPC with gogoprotobuf and the wider grpc-ecosystem.


## License
This software is licensed under the 3-Clause BSD License
("BSD License 2.0", "Revised BSD License", "New BSD License", or "Modified BSD License").


