golang/protobuf

repository·master·Indexed 27 days ago

https://github.com/golang/protobuf

Go support for Protocol Buffers, providing bindings and tools for serialization, JSON conversion, and code generation via the protoc-gen-go plugin. This legacy module includes packages such as proto, jsonpb, and ptypes. Note that this module is superseded by google.golang.org/protobuf.

Tokens
802
Snippets
1
Records
6
Agent score
45%

What's inside golang-protobuf

  1. Overview of github.com/golang/protobuf packages

    master

    The github.com/golang/protobuf module provides several packages for working with protocol buffers in Go:

    • proto: Functions for operating on protobuf messages (cloning, merging, equality checking, binary and text serialization).
    • jsonpb: Serialization of protobuf messages as JSON.
    • ptypes: Helper functionality for protobuf well-known types.
    • ptypes/any: Generated package for google/protobuf/any.proto.
    • ptypes/empty: Generated package for google/protobuf/empty.proto.
    • ptypes/timestamp: Generated package for google/protobuf/timestamp.proto.
    • ptypes/duration: Generated package for google/protobuf/duration.proto.
    • ptypes/wrappers: Generated package for google/protobuf/wrappers.proto.
    • ptypes/struct: Generated package for google/protobuf/struct.proto.
    • protoc-gen-go/descriptor: Generated package for google/protobuf/descriptor.proto.
    • protoc-gen-go/plugin: Generated package for google/protobuf/compiler/plugin.proto.
    • protoc-gen-go: A protoc plugin binary used to generate Go protocol buffer packages.
  2. Use the updated google.golang.org/protobuf module

    master

    The github.com/golang/protobuf module is superseded by google.golang.org/protobuf. The newer module provides an updated and simplified API, support for protobuf reflection, and other improvements.

    Recommendation: New code should use the google.golang.org/protobuf module instead of the legacy github.com/golang/protobuf module.

  3. Compatibility and breaking changes in github.com/golang/protobuf

    master

    While the module and generated code are intended to be stable, breaking changes may occur without notice due to:

    • Security: Resolving security issues in the specification or implementation.
    • Unspecified behavior: Changes to aspects of the protobuf specification that are currently undefined.
    • Specification changes: Addressing inconsistencies or incompleteness in the protobuf specification.
    • Bugs: Fixing bugs that violate correctness.
    • Generated additions: Adding new declarations (constants, variables, functions, types, fields, methods) to generated Go packages. Note: Injecting additional code on top of protoc-gen-go output is not supported.
    • Internal changes: Modifications to unexported declarations or the internal and generator packages.

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

  4. Use protoc-gen-go with protoc

    master

    Invoke the plugin through the protoc command using the --go_out flag. For example, using paths=source_relative will generate Go bindings in the same directory as your proto file with a .pb.go extension.

    protoc --go_out=paths=source_relative:. path/to/file.proto
  5. Configure protoc-gen-go flags

    master

    The protoc-gen-go plugin supports the following command-line flags when invoked via protoc:

    • plugins: A comma-separated list of plugins to enable. Currently, the supported value is grpc.
    • import_prefix: A string prefix to prepend to all generated import paths (except for standard library imports like context, fmt, and math).