protobuf

module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2018 License: BSD-3-Clause

README

Protocol Buffers for Go with Gadgets

Build Status GoDoc

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

Users

These projects use gogoprotobuf:

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

Mentioned

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.9 and 1.10 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.5.1 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

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

Directories

Path Synopsis
conformance implements the conformance test subprocess protocol as documented in conformance.proto.
conformance implements the conformance test subprocess protocol as documented in conformance.proto.
Package gogoproto provides extensions for protocol buffers to achieve: - fast marshalling and unmarshalling.
Package gogoproto provides extensions for protocol buffers to achieve: - fast marshalling and unmarshalling.
Package jsonpb provides marshaling and unmarshaling between protocol buffers and JSON.
Package jsonpb provides marshaling and unmarshaling between protocol buffers and JSON.
plugin
defaultcheck
The defaultcheck plugin is used to check whether nullable is not used incorrectly.
The defaultcheck plugin is used to check whether nullable is not used incorrectly.
description
The description (experimental) plugin generates a Description method for each message.
The description (experimental) plugin generates a Description method for each message.
embedcheck
The embedcheck plugin is used to check whether embed is not used incorrectly.
The embedcheck plugin is used to check whether embed is not used incorrectly.
enumstringer
The enumstringer (experimental) plugin generates a String method for each enum.
The enumstringer (experimental) plugin generates a String method for each enum.
equal
The equal plugin generates an Equal and a VerboseEqual method for each message.
The equal plugin generates an Equal and a VerboseEqual method for each message.
face
The face plugin generates a function will be generated which can convert a structure which satisfies an interface (face) to the specified structure.
The face plugin generates a function will be generated which can convert a structure which satisfies an interface (face) to the specified structure.
gostring
The gostring plugin generates a GoString method for each message.
The gostring plugin generates a GoString method for each message.
marshalto
The marshalto plugin generates a Marshal and MarshalTo method for each message.
The marshalto plugin generates a Marshal and MarshalTo method for each message.
oneofcheck
The oneofcheck plugin is used to check whether oneof is not used incorrectly.
The oneofcheck plugin is used to check whether oneof is not used incorrectly.
populate
The populate plugin generates a NewPopulated function.
The populate plugin generates a NewPopulated function.
size
The size plugin generates a Size or ProtoSize method for each message.
The size plugin generates a Size or ProtoSize method for each message.
stringer
The stringer plugin generates a String method for each message.
The stringer plugin generates a String method for each message.
testgen
The testgen plugin generates Test and Benchmark functions for each message.
The testgen plugin generates Test and Benchmark functions for each message.
union
The onlyone plugin generates code for the onlyone extension.
The onlyone plugin generates code for the onlyone extension.
unmarshal
The unmarshal plugin generates a Unmarshal method for each message.
The unmarshal plugin generates a Unmarshal method for each message.
Package proto converts data structures to and from the wire format of protocol buffers.
Package proto converts data structures to and from the wire format of protocol buffers.
protoc-gen-gogo
descriptor
Package descriptor provides functions for obtaining protocol buffer descriptors for generated Go types.
Package descriptor provides functions for obtaining protocol buffer descriptors for generated Go types.
generator
The code generator for the plugin for the Google protocol buffer compiler.
The code generator for the plugin for the Google protocol buffer compiler.
generator/internal/remap
Package remap handles tracking the locations of Go tokens in a source text across a rewrite by the Go formatter.
Package remap handles tracking the locations of Go tokens in a source text across a rewrite by the Go formatter.
grpc
Package grpc outputs gRPC service descriptions in Go code.
Package grpc outputs gRPC service descriptions in Go code.
custom
Package custom contains custom types for test and example purposes.
Package custom contains custom types for test and example purposes.
custom-dash-type
Package custom contains custom types for test and example purposes.
Package custom contains custom types for test and example purposes.
mapdefaults
Package mapdefaults is a generated protocol buffer package.
Package mapdefaults is a generated protocol buffer package.
typedeclimport
Package typedeclimport is a generated protocol buffer package.
Package typedeclimport is a generated protocol buffer package.
typedeclimport/subpkg
Package subpkg is a generated protocol buffer package.
Package subpkg is a generated protocol buffer package.
Package types contains code for interacting with well-known types.
Package types contains code for interacting with well-known types.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL