Introducing protobuf-go-lite, a streamlined Protobuf solution for Go that forsakes reflection for enhanced efficiency. By leveraging static code generation, it produces smaller binaries and improves runtime speed. Ideal for projects needing compatibility with TinyGo, this library is designed for developers seeking modularity and performance without compromise.
protobuf-go-lite is an innovative and lightweight implementation of Protocol Buffers tailored for Go, designed specifically to operate without reflection. By merging the code generator from protobuf-go with the modular features of vtprotobuf, it enables static code generation for critical operations such as marshal/unmarshal, size calculation, cloning, and equality checking. This streamlined approach results in enhanced runtime efficiency and notably smaller binaries, making it an ideal choice, especially when using TinyGo, which has limited support for reflection.
Although protobuf-go-lite supports a range of features, it currently does not include support for field masks and extensions.
Key Features:
- Static Code Generation: Unlike traditional methods involving reflection, static code generation simplifies and speeds up performance, leading to reduced memory allocation and optimized processing.
- Ecosystem Compatibility: This tool is compatible with lightweight Protobuf 3 RPCs, available through the StaRPC framework for both Go and TypeScript. For documentation generation, the use of protoc-gen-doc is suggested.
- Supports JSON Serialization: The package includes a fork of protoc-gen-go-json enabling seamless JSON marshaling and unmarshaling.
Usage Overview:
With protobuf-go-lite, you can expect the following helper methods for increased performance:
- Marshal: Includes memory-efficient functions like
MarshalVT()
andMarshalToVT(data []byte)
, crucial for efficiently handling serialization without reflection. - Size Calculation: The
SizeVT()
function accurately determines the size of your Protocol Buffers without the overhead of reflection. - Cloning: Implements cloning through
CloneVT()
, providing a speedy alternative to conventional cloning methods.
Example:
To see protobuf-go-lite in action, refer to the protobuf-project, which serves as a comprehensive template illustrating its integration with vtprotobuf and protowrap for generating Protocol Buffers.
Available at github.com/aperturerobotics/protobuf-go-lite, this repository is your go-to solution for efficient, reflection-free Protobuf handling in Go.