gogoproto

module
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: BSD-3-Clause

README

Protocol Buffers for Go with Gadgets

Cosmos's fork of gogo/protobuf.

Build Status GoDoc

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

More information in the original readme.

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/cosmos/gogoproto/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/cosmos/gogoproto/proto
go get github.com/cosmos/gogoproto/{binary}
go get github.com/cosmos/gogoproto/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/cosmos/gogoproto/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/cosmos/gogoproto/protobuf --{binary}_out=\
Mgoogle/protobuf/any.proto=github.com/cosmos/gogoproto/types,\
Mgoogle/protobuf/duration.proto=github.com/cosmos/gogoproto/types,\
Mgoogle/protobuf/struct.proto=github.com/cosmos/gogoproto/types,\
Mgoogle/protobuf/timestamp.proto=github.com/cosmos/gogoproto/types,\
Mgoogle/protobuf/wrappers.proto=github.com/cosmos/gogoproto/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/cosmos/gogoproto/proto
go get github.com/cosmos/gogoproto/jsonpb
go get github.com/cosmos/gogoproto/protoc-gen-gogo
go get github.com/cosmos/gogoproto/gogoproto

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:
Package gogoproto provides extensions for protocol buffers to achieve:
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.
Package types contains code for interacting with well-known types.
Package types contains code for interacting with well-known types.
any
Package types defines a custom wrapper for google.protobuf.Any which supports cached values as well as InterfaceRegistry which keeps track of types which can be used with Any for both security and introspection
Package types defines a custom wrapper for google.protobuf.Any which supports cached values as well as InterfaceRegistry which keeps track of types which can be used with Any for both security and introspection

Jump to

Keyboard shortcuts

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