Go support for Protocol Buffers

GoDev Build Status

This project hosts the Go implementation for protocol buffers, which is a language-neutral, platform-neutral, extensible mechanism for serializing structured data. The protocol buffer language is a language for specifying the schema for structured data. This schema is compiled into language specific bindings. This project provides both a tool to generate Go code for the protocol buffer language, and also the runtime implementation to handle serialization of messages in Go. See the protocol buffer developer guide for more information about protocol buffers themselves.

This project is comprised of two components:

See the developer guide for protocol buffers in Go for a general guide for how to get started using protobufs in Go.

google.golang.org/protobufgithub.com/golang/protobuf

Package index

Summary of the packages provided by this module:

Reporting issues

The issue tracker for this project is currently located at golang/protobuf.

Please report any issues there with a sufficient description of the bug or feature request. Bug reports should ideally be accompanied by a minimal reproduction of the issue. Irreproducible bugs are difficult to diagnose and fix (and likely to be closed after some period of time). Bug reports must specify the version of the Go protocol buffer module and also the version of the protocol buffer toolchain being used.

Contributing

This project is open-source and accepts contributions. See the contribution guide for more information.

Compatibility

This module and the generated code are expected to be stable over time. However, we reserve the right to make breaking changes without notice for the following reasons:

.protoprotoc-gen-goprotoc-gen-go/internal_gengoruntime/protoimplinternal

Any breaking changes outside of these will be announced 6 months in advance to protobuf@googlegroups.com.

protoc-gen-goprotoimpl.EnforceVersion

Historical legacy

google.golang.org/protobufgithub.com/golang/protobuf

The first version predates the release of Go 1 by several years. It has a long history as one of the first core pieces of infrastructure software ever written in Go. As such, the Go protobuf project was one of many pioneers for determining what the Go language should even look like and what would eventually be considered good design patterns and “idiomatic” Go (by simultaneously being both positive and negative examples of it).

proto.Unmarshal

These changes demonstrate the difficulty of determining what the right API is for any new technology. It takes time multiplied by many users to determine what is best; even then, “best” is often still somewhere over the horizon.

The change on June 6th, 2012 added a degree of type-safety to Go protobufs by declaring a new interface that all protobuf messages were required to implement:

proto.UnmarshalProtoMessage
protoc-gen-goprotoc-gen-gointerface{}
proto.Messageprotoc-gen-go
proto.Message
proto.Messageproto.Marshalproto.Equalproto.Marshalerproto.Messagetrace_idTraceIdprotoc-gen-go

Both of these issues are solved by following the idiom that interfaces should describe behavior, not data. This means that the interface itself should provide sufficient functionality through its methods that users can introspect and interact with all aspects of a protobuf message through a principled API. This feature is called protobuf reflection. Just as how Go reflection provides an API for programmatically interacting with any arbitrary Go value, protobuf reflection provides an API for programmatically interacting with any arbitrary protobuf message.

proto.Message
proto.MessageProtoReflectprotoreflect.Messageproto.Messageproto.Message

The goal for this major revision is to improve upon all the benefits of, while addressing all the shortcomings of the old API. We hope that it will serve the Go ecosystem well for the next 10 years and beyond.