Bumps [github.com/checkpoint-restore/go-criu/v8](https://github.com/checkpoint-restore/go-criu) from 8.3.0 to 8.4.0. - [Release notes](https://github.com/checkpoint-restore/go-criu/releases) - [Commits](https://github.com/checkpoint-restore/go-criu/compare/v8.3.0...v8.4.0) --- updated-dependencies: - dependency-name: github.com/checkpoint-restore/go-criu/v8 dependency-version: 8.4.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
protobuf-go-lite
protobuf-go-lite is a stripped-down version of the protobuf-go code generator modified to work without reflection and merged with vtprotobuf to provide modular features with static code generation for marshal/unmarshal, size, clone, equal, text, and JSON. JSON support is derived from a fork of protoc-gen-go-json.
Static code generation without reflection is more efficient at runtime and results in smaller code binaries. It also provides better support for tinygo which has limited reflection support.
protobuf-go-lite supports Edition 2024 schemas that resolve to the open Go API
and static, reflect-free generated output. The default features=all path
supports explicit and implicit presence, legacy required fields, packed
encoding, delimited message encoding, oneofs, maps, clone/equal, text,
unmarshal, unsafe unmarshal, and JSON when the resolved JSON format is
ALLOW.
Generated output is static Go code. The default codegen=helper mode emits
message methods that call small concrete helpers from the root
protobuf-go-lite runtime package to keep generated .pb.go files smaller.
The fallback codegen=unrolled mode keeps the older inline method-body shape
for helper-converted method families when callers need to inspect or compare
that output. Neither mode relies on Go reflection, descriptors, struct tags, or
runtime type metadata for generated marshal, unmarshal, size, clone, equal,
text, or JSON behavior.
protobuf-go-lite rejects Edition schemas that require closed enum semantics,
LEGACY_BEST_EFFORT JSON, or explicit hybrid/opaque Go APIs. It does not
support fieldmasks and extensions.
Ecosystem
Lightweight Protobuf 3 RPCs are implemented in StaRPC for Go and TypeScript.
protoc-gen-doc is recommended for generating documentation.
protobuf-es-lite is recommended for lightweight TypeScript protobufs.
Protobuf
protocol buffers are a cross-platform cross-language message serialization format. Protobuf 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.
Example
See the protobuf-project template for an example of how to use this package and vtprotobuf together with protowrap to generate protobufs for your project.
This package is available at github.com/aperturerobotics/protobuf-go-lite.
Package index
Summary of the packages provided by this module:
compiler/protogen: Packageprotogenprovides support for writing protoc plugins.cmd/protoc-gen-go-lite: Theprotoc-gen-go-litebinary is a protoc plugin to generate a Go protocol buffer package.
Usage
-
Install
protoc-gen-go-lite:go install github.com/aperturerobotics/protobuf-go-lite/cmd/protoc-gen-go-lite@latest -
Update your
protocgenerator to use the new plug-in.for name in $(PROTO_SRC_NAMES); do \ protoc \ --plugin protoc-gen-go-lite="${GOBIN}/protoc-gen-go-lite" \ --go-lite_out=. \ --go-lite_opt=features=marshal+unmarshal+size+equal+clone+text \ proto/$${name}.proto; \ done
protobuf-go-lite replaces protoc-gen-go and protoc-gen-go-vtprotobuf and should not be used with those generators.
Check out the template for a quick start!
Code generation modes
protoc-gen-go-lite accepts codegen=helper and codegen=unrolled:
codegen=helperis the default. It emits static message methods that call concrete runtime helpers such as encode, decode, clone/equal, size, and text helpers.codegen=unrolledemits the older inline method-body style for helper-converted method families. Select it by addingcodegen=unrolledto--go-lite_opt.
Both modes are selected at generation time and produce normal Go packages for callers. They do not add a reflection registry, descriptor builder, struct tag interpreter, or runtime type-metadata dependency to generated fast paths.
Generated output
Generated .pb.go files are checked in for this repository's fixtures and
well-known type packages. After changing the generator or runtime helpers,
regenerate and verify them with the GNU Make targets:
gmake gengo
gmake check-gengo
On systems where make is GNU Make, make check-gengo is equivalent. On macOS,
use gmake so the same GNU Make behavior is used locally and in Linux CI.
Available features
The following additional features can be enabled:
-
size: generates afunc (p *YourProto) SizeVT() inthelper that behaves identically to callingproto.Size(p)on the message, except the size calculation is static generated code and does not use reflection. This helper function can be used directly, and it'll also be used by themarshalcodegen to ensure the destination buffer is properly sized before ProtoBuf objects are marshalled to it. -
equal: generates the following helper methods-
func (this *YourProto) EqualVT(that *YourProto) bool: this function behaves almost identically to callingproto.Equal(this, that)on messages, except the equality calculation is static generated code and does not use reflection. This helper function can be used directly. -
func (this *YourProto) EqualMessageVT(thatMsg any) bool: this function behaves like the abovethis.EqualVT(that), but allows comparing against arbitrary proto messages. IfthatMsgis not of type*YourProto, false is returned. The uniform signature provided by this method allows accessing this method via type assertions even if the message type is not known at compile time. This allows implementing a genericfunc EqualVT(proto.Message, proto.Message) boolwithout reflection.
-
-
marshal: generates the following helper methods-
func (p *YourProto) MarshalVT() ([]byte, error): this function behaves identically to callingproto.Marshal(p), except the actual marshalling is static generated code and does not use reflection or allocate memory. This function simply allocates a properly sized buffer by callingSizeVTon the message and then usesMarshalToSizedBufferVTto marshal to it. -
func (p *YourProto) MarshalToVT(data []byte) (int, error): this function can be used to marshal a message to an existing buffer. The buffer must be large enough to hold the marshalled message, otherwise this function will panic. It returns the number of bytes marshalled. This function is useful e.g. when using memory pooling to re-use serialization buffers. -
func (p *YourProto) MarshalToSizedBufferVT(data []byte) (int, error): this function behaves likeMarshalTobut expects that the input buffer has the exact size required to hold the message, otherwise it will panic.
-
-
marshal_strict: generates the following helper methods-
func (p *YourProto) MarshalVTStrict() ([]byte, error): this function behaves likeMarshalVT, except fields are marshalled in a strict order by field's numbers they were declared in .proto file. -
func (p *YourProto) MarshalToVTStrict(data []byte) (int, error): this function behaves likeMarshalToVT, except fields are marshalled in a strict order by field's numbers they were declared in .proto file. -
func (p *YourProto) MarshalToSizedBufferVTStrict(data []byte) (int, error): this function behaves likeMarshalToSizedBufferVT, except fields are marshalled in a strict order by field's numbers they were declared in .proto file.
-
-
unmarshal: generates afunc (p *YourProto) UnmarshalVT(data []byte)that behaves similarly to callingproto.Unmarshal(data, p)on the message, except the unmarshalling is performed by static generated code without using reflection and allocating as little memory as possible. If the receiverpis not fully zeroed-out, the unmarshal call will actually behave likeproto.Merge(data, p). This is because theproto.Unmarshalin the ProtoBuf API is implemented by resetting the destination message and then callingproto.Mergeon it. To ensure properUnmarshalsemantics, ensure you've calledproto.Reseton your message before callingUnmarshalVT, or that your message has been newly allocated. -
unmarshal_unsafegenerates afunc (p *YourProto) UnmarshalVTUnsafe(data []byte)that behaves likeUnmarshalVT, except it unsafely casts slices of data tobytesandstringfields instead of copying them to newly allocated arrays, so that it performs less allocations. Data received from the wire has to be left untouched for the lifetime of the message. Otherwise, the message'sbytesandstringfields can be corrupted. -
clone: generates the following helper methods-
func (p *YourProto) CloneVT() *YourProto: this function behaves similarly to callingproto.Clone(p)on the message, except the cloning is performed by static generated code without using reflection. If the receiverpisnila typednilis returned. -
func (p *YourProto) CloneMessageVT() any: this function behaves like the abovep.CloneVT(), but provides a uniform signature in order to be accessible via type assertions even if the type is not known at compile time. This allows implementing a genericfunc CloneMessageVT() anywithout reflection. If the receiverpisnil, a typednilpointer of the message type will be returned inside aanyinterface.
-
-
json: generates the following helper methods-
func (p *YourProto) UnmarshalJSON(data []byte) errorbehaves similarly to callingprotojson.Unmarshal(data, p)on the message, except the unmarshalling is performed by static generated code without using reflection and allocating as little memory as possible. If the receiverpis not fully zeroed-out, the unmarshal call will actually behave likeproto.Merge(data, p). To ensure properUnmarshalsemantics, ensure you've calledproto.Reseton your message before callingUnmarshalJSON, or that your message has been newly allocated. -
func (p *YourProto) UnmarshalJSONValue(val *fastjson.Value) errorunmarshals a*fastjson.Value. -
func (p *YourProto) MarshalJSON() ([]byte, error)behaves similarly to callingprotojson.Marshal(p)on the message, except the marshalling is performed by static generated code without using reflection and allocating as little memory as possible. -
Adding a
//protobuf-go-lite:disable-jsoncomment before a message or enum will disable the json marshaler / unmarshaler.
-
-
text: generatesMarshalProtoText() stringandString() stringmethods that emit protobuf text-format-style output using static generated code without reflection. Adding a//protobuf-go-lite:disable-textcomment before a message disables text generation for that message.
License
BSD-3