• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

_conformance/H07-Mar-2017-

codec/H07-Mar-2017-

gogoproto/H07-Mar-2017-

gogoreplace/H07-Mar-2017-

io/H07-Mar-2017-

jsonpb/H07-Mar-2017-

plugin/H07-Mar-2017-

proto/H07-Mar-2017-

protobuf/H07-Mar-2017-

protoc-gen-combo/H07-Mar-2017-

protoc-gen-gofast/H07-Mar-2017-

protoc-gen-gogo/H07-Mar-2017-

protoc-gen-gogofast/H07-Mar-2017-

protoc-gen-gogofaster/H07-Mar-2017-

protoc-gen-gogoslick/H07-Mar-2017-

protoc-gen-gogotypes/H07-Mar-2017-

protoc-gen-gostring/H07-Mar-2017-

protoc-min-version/H07-Mar-2017-

sortkeys/H07-Mar-2017-

test/H07-Mar-2017-

types/H07-Mar-2017-

vanity/H07-Mar-2017-

version/H07-Mar-2017-

.gitignoreH A D07-Mar-201718

.mailmapH A D07-Mar-2017551

.travis.ymlH A D07-Mar-2017510

AUTHORSH A D07-Mar-2017548

CONTRIBUTORSH A D07-Mar-2017667

GOLANG_CONTRIBUTORSH A D07-Mar-2017218

LICENSEH A D07-Mar-20171.7 KiB

MakefileH A D07-Mar-20174.7 KiB

READMEH A D07-Mar-201710.3 KiB

Readme.mdH A D07-Mar-20177.5 KiB

bench.mdH A D07-Mar-201715 KiB

custom_types.mdH A D07-Mar-20172.4 KiB

extensions.mdH A D07-Mar-201715.9 KiB

install-protobuf.shH A D07-Mar-2017504

README

1GoGoProtobuf http://github.com/gogo/protobuf extends
2GoProtobuf http://github.com/golang/protobuf
3
4# Go support for Protocol Buffers
5
6Google's data interchange format.
7Copyright 2010 The Go Authors.
8https://github.com/golang/protobuf
9
10This package and the code it generates requires at least Go 1.4.
11
12This software implements Go bindings for protocol buffers.  For
13information about protocol buffers themselves, see
14	https://developers.google.com/protocol-buffers/
15
16## Installation ##
17
18To use this software, you must:
19- Install the standard C++ implementation of protocol buffers from
20	https://developers.google.com/protocol-buffers/
21- Of course, install the Go compiler and tools from
22	https://golang.org/
23  See
24	https://golang.org/doc/install
25  for details or, if you are using gccgo, follow the instructions at
26	https://golang.org/doc/install/gccgo
27- Grab the code from the repository and install the proto package.
28  The simplest way is to run `go get -u github.com/golang/protobuf/{proto,protoc-gen-go}`.
29  The compiler plugin, protoc-gen-go, will be installed in $GOBIN,
30  defaulting to $GOPATH/bin.  It must be in your $PATH for the protocol
31  compiler, protoc, to find it.
32
33This software has two parts: a 'protocol compiler plugin' that
34generates Go source files that, once compiled, can access and manage
35protocol buffers; and a library that implements run-time support for
36encoding (marshaling), decoding (unmarshaling), and accessing protocol
37buffers.
38
39There is support for gRPC in Go using protocol buffers.
40See the note at the bottom of this file for details.
41
42There are no insertion points in the plugin.
43
44GoGoProtobuf provides extensions for protocol buffers and GoProtobuf
45see http://github.com/gogo/protobuf/gogoproto/doc.go
46
47## Using protocol buffers with Go ##
48
49Once the software is installed, there are two steps to using it.
50First you must compile the protocol buffer definitions and then import
51them, with the support library, into your program.
52
53To compile the protocol buffer definition, run protoc with the --gogo_out
54parameter set to the directory you want to output the Go code to.
55
56	protoc --gogo_out=. *.proto
57
58The generated files will be suffixed .pb.go.  See the Test code below
59for an example using such a file.
60
61The package comment for the proto library contains text describing
62the interface provided in Go for protocol buffers. Here is an edited
63version.
64
65If you are using any gogo.proto extensions you will need to specify the
66proto_path to include the descriptor.proto and gogo.proto.
67gogo.proto is located in github.com/gogo/protobuf/gogoproto
68This should be fine, since your import is the same.
69descriptor.proto is located in either github.com/gogo/protobuf/protobuf
70or code.google.com/p/protobuf/trunk/src/
71Its import is google/protobuf/descriptor.proto so it might need some help.
72
73	protoc --gogo_out=. -I=.:github.com/gogo/protobuf/protobuf *.proto
74
75==========
76
77The proto package converts data structures to and from the
78wire format of protocol buffers.  It works in concert with the
79Go source code generated for .proto files by the protocol compiler.
80
81A summary of the properties of the protocol buffer interface
82for a protocol buffer variable v:
83
84  - Names are turned from camel_case to CamelCase for export.
85  - There are no methods on v to set fields; just treat
86  	them as structure fields.
87  - There are getters that return a field's value if set,
88	and return the field's default value if unset.
89	The getters work even if the receiver is a nil message.
90  - The zero value for a struct is its correct initialization state.
91	All desired fields must be set before marshaling.
92  - A Reset() method will restore a protobuf struct to its zero state.
93  - Non-repeated fields are pointers to the values; nil means unset.
94	That is, optional or required field int32 f becomes F *int32.
95  - Repeated fields are slices.
96  - Helper functions are available to aid the setting of fields.
97	Helpers for getting values are superseded by the
98	GetFoo methods and their use is deprecated.
99		msg.Foo = proto.String("hello") // set field
100  - Constants are defined to hold the default values of all fields that
101	have them.  They have the form Default_StructName_FieldName.
102	Because the getter methods handle defaulted values,
103	direct use of these constants should be rare.
104  - Enums are given type names and maps from names to values.
105	Enum values are prefixed with the enum's type name. Enum types have
106	a String method, and a Enum method to assist in message construction.
107  - Nested groups and enums have type names prefixed with the name of
108  	the surrounding message type.
109  - Extensions are given descriptor names that start with E_,
110	followed by an underscore-delimited list of the nested messages
111	that contain it (if any) followed by the CamelCased name of the
112	extension field itself.  HasExtension, ClearExtension, GetExtension
113	and SetExtension are functions for manipulating extensions.
114  - Oneof field sets are given a single field in their message,
115	with distinguished wrapper types for each possible field value.
116  - Marshal and Unmarshal are functions to encode and decode the wire format.
117
118When the .proto file specifies `syntax="proto3"`, there are some differences:
119
120  - Non-repeated fields of non-message type are values instead of pointers.
121  - Getters are only generated for message and oneof fields.
122  - Enum types do not get an Enum method.
123
124Consider file test.proto, containing
125
126```proto
127	package example;
128
129	enum FOO { X = 17; };
130
131	message Test {
132	  required string label = 1;
133	  optional int32 type = 2 [default=77];
134	  repeated int64 reps = 3;
135	  optional group OptionalGroup = 4 {
136	    required string RequiredField = 5;
137	  }
138	}
139```
140
141To create and play with a Test object from the example package,
142
143```go
144	package main
145
146	import (
147		"log"
148
149		"github.com/gogo/protobuf/proto"
150		"path/to/example"
151	)
152
153	func main() {
154		test := &example.Test {
155			Label: proto.String("hello"),
156			Type:  proto.Int32(17),
157			Reps:  []int64{1, 2, 3},
158			Optionalgroup: &example.Test_OptionalGroup {
159				RequiredField: proto.String("good bye"),
160			},
161		}
162		data, err := proto.Marshal(test)
163		if err != nil {
164			log.Fatal("marshaling error: ", err)
165		}
166		newTest := &example.Test{}
167		err = proto.Unmarshal(data, newTest)
168		if err != nil {
169			log.Fatal("unmarshaling error: ", err)
170		}
171		// Now test and newTest contain the same data.
172		if test.GetLabel() != newTest.GetLabel() {
173			log.Fatalf("data mismatch %q != %q", test.GetLabel(), newTest.GetLabel())
174		}
175		// etc.
176	}
177```
178
179
180## Parameters ##
181
182To pass extra parameters to the plugin, use a comma-separated
183parameter list separated from the output directory by a colon:
184
185
186	protoc --gogo_out=plugins=grpc,import_path=mypackage:. *.proto
187
188
189- `import_prefix=xxx` - a prefix that is added onto the beginning of
190  all imports. Useful for things like generating protos in a
191  subdirectory, or regenerating vendored protobufs in-place.
192- `import_path=foo/bar` - used as the package if no input files
193  declare `go_package`. If it contains slashes, everything up to the
194  rightmost slash is ignored.
195- `plugins=plugin1+plugin2` - specifies the list of sub-plugins to
196  load. The only plugin in this repo is `grpc`.
197- `Mfoo/bar.proto=quux/shme` - declares that foo/bar.proto is
198  associated with Go package quux/shme.  This is subject to the
199  import_prefix parameter.
200
201## gRPC Support ##
202
203If a proto file specifies RPC services, protoc-gen-go can be instructed to
204generate code compatible with gRPC (http://www.grpc.io/). To do this, pass
205the `plugins` parameter to protoc-gen-go; the usual way is to insert it into
206the --go_out argument to protoc:
207
208	protoc --gogo_out=plugins=grpc:. *.proto
209
210## Compatibility ##
211
212The library and the generated code are expected to be stable over time.
213However, we reserve the right to make breaking changes without notice for the
214following reasons:
215
216- Security. A security issue in the specification or implementation may come to
217  light whose resolution requires breaking compatibility. We reserve the right
218  to address such security issues.
219- Unspecified behavior.  There are some aspects of the Protocol Buffers
220  specification that are undefined.  Programs that depend on such unspecified
221  behavior may break in future releases.
222- Specification errors or changes. If it becomes necessary to address an
223  inconsistency, incompleteness, or change in the Protocol Buffers
224  specification, resolving the issue could affect the meaning or legality of
225  existing programs.  We reserve the right to address such issues, including
226  updating the implementations.
227- Bugs.  If the library has a bug that violates the specification, a program
228  that depends on the buggy behavior may break if the bug is fixed.  We reserve
229  the right to fix such bugs.
230- Adding methods or fields to generated structs.  These may conflict with field
231  names that already exist in a schema, causing applications to break.  When the
232  code generator encounters a field in the schema that would collide with a
233  generated field or method name, the code generator will append an underscore
234  to the generated field or method name.
235- Adding, removing, or changing methods or fields in generated structs that
236  start with `XXX`.  These parts of the generated code are exported out of
237  necessity, but should not be considered part of the public API.
238- Adding, removing, or changing unexported symbols in generated code.
239
240Any breaking changes outside of these will be announced 6 months in advance to
241protobuf@googlegroups.com.
242
243You should, whenever possible, use generated code created by the `protoc-gen-go`
244tool built at the same commit as the `proto` package.  The `proto` package
245declares package-level constants in the form `ProtoPackageIsVersionX`.
246Application code and generated code may depend on one of these constants to
247ensure that compilation will fail if the available version of the proto library
248is too old.  Whenever we make a change to the generated code that requires newer
249library support, in the same commit we will increment the version number of the
250generated code and declare a new package-level constant whose name incorporates
251the latest version number.  Removing a compatibility constant is considered a
252breaking change and would be subject to the announcement policy stated above.
253
254## Plugins ##
255
256The `protoc-gen-go/generator` package exposes a plugin interface,
257which is used by the gRPC code generation. This interface is not
258supported and is subject to incompatible changes without notice.
259

Readme.md

1# Protocol Buffers for Go with Gadgets
2
3[![Build Status](https://travis-ci.org/gogo/protobuf.svg?branch=master)](https://travis-ci.org/gogo/protobuf)
4
5gogoprotobuf is a fork of <a href="https://github.com/golang/protobuf">golang/protobuf</a> with extra code generation features.
6
7This code generation is used to achieve:
8
9  - fast marshalling and unmarshalling
10  - more canonical Go structures
11  - goprotobuf compatibility
12  - less typing by optionally generating extra helper code
13  - peace of mind by optionally generating test and benchmark code
14  - other serialization formats
15
16Keeping track of how up to date gogoprotobuf is relative to golang/protobuf is done in this
17<a href="https://github.com/gogo/protobuf/issues/191">issue</a>
18
19## Users
20
21These projects use gogoprotobuf:
22
23  - <a href="http://godoc.org/github.com/coreos/etcd">etcd</a> - <a href="https://blog.gopheracademy.com/advent-2015/etcd-distributed-key-value-store-with-grpc-http2/">blog</a> - <a href="https://github.com/coreos/etcd/blob/master/etcdserver/etcdserverpb/etcdserver.proto">sample proto file</a>
24  - <a href="https://www.spacemonkey.com/">spacemonkey</a> - <a href="https://www.spacemonkey.com/blog/posts/go-space-monkey">blog</a>
25  - <a href="http://badoo.com">badoo</a> - <a href="https://github.com/badoo/lsd/blob/32061f501c5eca9c76c596d790b450501ba27b2f/proto/lsd.proto">sample proto file</a>
26  - <a href="https://github.com/mesos/mesos-go">mesos-go</a> - <a href="https://github.com/mesos/mesos-go/blob/f9e5fb7c2f50ab5f23299f26b6b07c5d6afdd252/api/v0/mesosproto/authentication.proto">sample proto file</a>
27  - <a href="https://github.com/mozilla-services/heka">heka</a> - <a href="https://github.com/mozilla-services/heka/commit/eb72fbf7d2d28249fbaf8d8dc6607f4eb6f03351">the switch from golang/protobuf to gogo/protobuf when it was still on code.google.com</a>
28  - <a href="https://github.com/cockroachdb/cockroach">cockroachdb</a> - <a href="https://github.com/cockroachdb/cockroach/blob/651d54d393e391a30154e9117ab4b18d9ee6d845/roachpb/metadata.proto">sample proto file</a>
29  - <a href="https://github.com/jbenet/go-ipfs">go-ipfs</a> - <a href="https://github.com/ipfs/go-ipfs/blob/2b6da0c024f28abeb16947fb452787196a6b56a2/merkledag/pb/merkledag.proto">sample proto file</a>
30  - <a href="https://github.com/philhofer/rkive">rkive-go</a> - <a href="https://github.com/philhofer/rkive/blob/e5dd884d3ea07b341321073882ae28aa16dd11be/rpbc/riak_dt.proto">sample proto file</a>
31  - <a href="https://www.dropbox.com">dropbox</a>
32  - <a href="https://srclib.org/">srclib</a> - <a href="https://github.com/sourcegraph/srclib/blob/6538858f0c410cac5c63440317b8d009e889d3fb/graph/def.proto">sample proto file</a>
33  - <a href="http://www.adyoulike.com/">adyoulike</a>
34  - <a href="http://www.cloudfoundry.org/">cloudfoundry</a> - <a href="https://github.com/cloudfoundry/bbs/blob/d673710b8c4211037805129944ee4c5373d6588a/models/events.proto">sample proto file</a>
35  - <a href="http://kubernetes.io/">kubernetes</a> - <a href="https://github.com/kubernetes/kubernetes/tree/88d8628137f94ee816aaa6606ae8cd045dee0bff/cmd/libs/go2idl">go2idl built on top of gogoprotobuf</a>
36  - <a href="https://dgraph.io/">dgraph</a> - <a href="https://github.com/dgraph-io/dgraph/releases/tag/v0.4.3">release notes</a> - <a href="https://discuss.dgraph.io/t/gogoprotobuf-is-extremely-fast/639">benchmarks</a></a>
37  - <a href="https://github.com/centrifugal/centrifugo">centrifugo</a> - <a href="https://forum.golangbridge.org/t/centrifugo-real-time-messaging-websocket-or-sockjs-server-v1-5-0-released/2861">release notes</a> - <a href="https://medium.com/@fzambia/centrifugo-protobuf-inside-json-outside-21d39bdabd68#.o3icmgjqd">blog</a>
38  - <a href="https://github.com/docker/swarmkit">docker swarmkit</a> - <a href="https://github.com/docker/swarmkit/blob/63600e01af3b8da2a0ed1c9fa6e1ae4299d75edb/api/objects.proto">sample proto file</a>
39  - <a href="https://nats.io/">nats.io</a> - <a href="https://github.com/nats-io/go-nats-streaming/blob/master/pb/protocol.proto">go-nats-streaming</a>
40  - <a href="https://github.com/pingcap/tidb">tidb</a> - Communication between <a href="https://github.com/pingcap/tipb/blob/master/generate-go.sh#L4">tidb</a> and <a href="https://github.com/pingcap/kvproto/blob/master/generate_go.sh#L3">tikv</a>
41  - <a href="https://github.com/AsynkronIT/protoactor-go">protoactor-go</a> - <a href="https://github.com/AsynkronIT/protoactor-go/blob/dev/protobuf/protoc-gen-protoactor/main.go">vanity command</a> that also generates actors from service definitions
42
43Please lets us know if you are using gogoprotobuf by posting on our <a href="https://groups.google.com/forum/#!topic/gogoprotobuf/Brw76BxmFpQ">GoogleGroup</a>.
44
45### Mentioned
46
47  - <a href="http://www.slideshare.net/albertstrasheim/serialization-in-go">Cloudflare - go serialization talk - Albert Strasheim</a>
48  - <a href="http://gophercon.sourcegraph.com/post/83747547505/writing-a-high-performance-database-in-go">gophercon</a>
49  - <a href="https://github.com/alecthomas/go_serialization_benchmarks">alecthomas' go serialization benchmarks</a>
50
51## Getting Started
52
53There are several ways to use gogoprotobuf, but for all you need to install go and protoc.
54After that you can choose:
55
56  - Speed
57  - More Speed and more generated code
58  - Most Speed and most customization
59
60### Installation
61
62To install it, you must first have Go (at least version 1.6.3) installed (see [http://golang.org/doc/install](http://golang.org/doc/install)).  Go 1.7.1 and 1.8 is continuously tested.
63
64Next, install the standard protocol buffer implementation from [https://github.com/google/protobuf](https://github.com/google/protobuf).
65Most versions from 2.3.1 should not give any problems, but 2.6.1, 3.0.2 and 3.1.0 are continuously tested.
66
67### Speed
68
69Install the protoc-gen-gofast binary
70
71    go get github.com/gogo/protobuf/protoc-gen-gofast
72
73Use it to generate faster marshaling and unmarshaling go code for your protocol buffers.
74
75    protoc --gofast_out=. myproto.proto
76
77This does not allow you to use any of the other gogoprotobuf [extensions](https://github.com/gogo/protobuf/blob/master/extensions.md).
78
79### More Speed and more generated code
80
81Fields without pointers cause less time in the garbage collector.
82More code generation results in more convenient methods.
83
84Other binaries are also included:
85
86    protoc-gen-gogofast (same as gofast, but imports gogoprotobuf)
87    protoc-gen-gogofaster (same as gogofast, without XXX_unrecognized, less pointer fields)
88    protoc-gen-gogoslick (same as gogofaster, but with generated string, gostring and equal methods)
89
90Installing any of these binaries is easy.  Simply run:
91
92    go get github.com/gogo/protobuf/proto
93    go get github.com/gogo/protobuf/{binary}
94    go get github.com/gogo/protobuf/gogoproto
95
96These binaries allow you to using gogoprotobuf [extensions](https://github.com/gogo/protobuf/blob/master/extensions.md).
97
98### Most Speed and most customization
99
100Customizing 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.
101gogoprotobuf also offers more serialization formats and generation of tests and even more methods.
102
103Please visit the [extensions](https://github.com/gogo/protobuf/blob/master/extensions.md) page for more documentation.
104
105Install protoc-gen-gogo:
106
107    go get github.com/gogo/protobuf/proto
108    go get github.com/gogo/protobuf/jsonpb
109    go get github.com/gogo/protobuf/protoc-gen-gogo
110    go get github.com/gogo/protobuf/gogoproto
111
112## GRPC
113
114It works the same as golang/protobuf, simply specify the plugin.
115Here is an example using gofast:
116
117    protoc --gofast_out=plugins=grpc:. my.proto
118