protobuf_go_lite

package module
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2026 License: BSD-3-Clause Imports: 13 Imported by: 110

README

protobuf-go-lite

GoDoc Widget DeepWiki Widget

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: Package protogen provides support for writing protoc plugins.
  • cmd/protoc-gen-go-lite: The protoc-gen-go-lite binary is a protoc plugin to generate a Go protocol buffer package.

Usage

  1. Install protoc-gen-go-lite:

    go install github.com/aperturerobotics/protobuf-go-lite/cmd/protoc-gen-go-lite@latest
    
  2. Update your protoc generator 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=helper is the default. It emits static message methods that call concrete runtime helpers such as encode, decode, clone/equal, size, and text helpers.
  • codegen=unrolled emits the older inline method-body style for helper-converted method families. Select it by adding codegen=unrolled to --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 a func (p *YourProto) SizeVT() int helper that behaves identically to calling proto.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 the marshal codegen 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 calling proto.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 above this.EqualVT(that), but allows comparing against arbitrary proto messages. If thatMsg is 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 generic func EqualVT(proto.Message, proto.Message) bool without reflection.

  • marshal: generates the following helper methods

    • func (p *YourProto) MarshalVT() ([]byte, error): this function behaves identically to calling proto.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 calling SizeVT on the message and then uses MarshalToSizedBufferVT to 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 like MarshalTo but 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 like MarshalVT, 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 like MarshalToVT, 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 like MarshalToSizedBufferVT, except fields are marshalled in a strict order by field's numbers they were declared in .proto file.

  • unmarshal: generates a func (p *YourProto) UnmarshalVT(data []byte) that behaves similarly to calling proto.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 receiver p is not fully zeroed-out, the unmarshal call will actually behave like proto.Merge(data, p). This is because the proto.Unmarshal in the ProtoBuf API is implemented by resetting the destination message and then calling proto.Merge on it. To ensure proper Unmarshal semantics, ensure you've called proto.Reset on your message before calling UnmarshalVT, or that your message has been newly allocated.

  • unmarshal_unsafe generates a func (p *YourProto) UnmarshalVTUnsafe(data []byte) that behaves like UnmarshalVT, except it unsafely casts slices of data to bytes and string fields 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's bytes and string fields can be corrupted.

  • clone: generates the following helper methods

    • func (p *YourProto) CloneVT() *YourProto: this function behaves similarly to calling proto.Clone(p) on the message, except the cloning is performed by static generated code without using reflection. If the receiver p is nil a typed nil is returned.

    • func (p *YourProto) CloneMessageVT() any: this function behaves like the above p.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 generic func CloneMessageVT() any without reflection. If the receiver p is nil, a typed nil pointer of the message type will be returned inside a any interface.

  • json: generates the following helper methods

    • func (p *YourProto) UnmarshalJSON(data []byte) error behaves similarly to calling protojson.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 receiver p is not fully zeroed-out, the unmarshal call will actually behave like proto.Merge(data, p). To ensure proper Unmarshal semantics, ensure you've called proto.Reset on your message before calling UnmarshalJSON, or that your message has been newly allocated.

    • func (p *YourProto) UnmarshalJSONValue(val *fastjson.Value) error unmarshals a *fastjson.Value.

    • func (p *YourProto) MarshalJSON() ([]byte, error) behaves similarly to calling protojson.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-json comment before a message or enum will disable the json marshaler / unmarshaler.

  • text: generates MarshalProtoText() string and String() string methods that emit protobuf text-format-style output using static generated code without reflection. Adding a //protobuf-go-lite:disable-text comment before a message disables text generation for that message.

License

BSD-3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidLength is returned when decoding a negative length.
	ErrInvalidLength = errors.New("proto: negative length found during unmarshaling")
	// ErrIntOverflow is returned when decoding a varint representation of an integer that overflows 64 bits.
	ErrIntOverflow = errors.New("proto: integer overflow")
	// ErrUnexpectedEndOfGroup is returned when decoding a group end without a corresponding group start.
	ErrUnexpectedEndOfGroup = errors.New("proto: unexpected end of group")
)

Functions

func AppendVarint added in v0.4.7

func AppendVarint(b []byte, v uint64) []byte

AppendVarint appends v to b as a varint-encoded uint64.

func CloneBytes added in v0.15.0

func CloneBytes[S ~[]byte](v S) S

CloneBytes clones one byte slice.

func CloneBytesMap added in v0.15.0

func CloneBytesMap[M ~map[K]V, K comparable, V ~[]byte](m M) M

CloneBytesMap clones a map whose values are bytes fields.

func CloneBytesSlice added in v0.15.0

func CloneBytesSlice[S ~[]E, E ~[]byte](s S) S

CloneBytesSlice clones a repeated bytes field.

func CloneMap added in v0.15.0

func CloneMap[M ~map[K]V, K comparable, V any](m M) M

CloneMap clones a map whose values do not need deep cloning.

func ClonePtr added in v0.15.0

func ClonePtr[T any](v *T) *T

ClonePtr clones one explicit scalar pointer.

func CloneSlice added in v0.15.0

func CloneSlice[S ~[]E, E any](s S) S

CloneSlice clones a scalar slice.

func CloneVTMap added in v0.15.0

func CloneVTMap[M ~map[K]V, K comparable, V CloneVT[V]](m M) M

CloneVTMap clones a map whose values are VT messages.

func CloneVTSlice added in v0.6.2

func CloneVTSlice[S ~[]E, E CloneVT[E]](s S) S

CloneVTSlice clones a slice of CloneVT messages.

func CloneVTValue added in v0.15.0

func CloneVTValue[T CloneVT[T]](v T) T

CloneVTValue clones one VT message value.

func CompareComparable

func CompareComparable[T comparable]() func(t1, t2 T) bool

CompareComparable returns a compare function to compare two comparable types.

func CompareEqualVT

func CompareEqualVT[T EqualVT[T]]() func(t1, t2 T) bool

CompareEqualVT returns a compare function to compare two VTProtobuf messages.

func ConsumeVarint added in v0.4.7

func ConsumeVarint(b []byte) (v uint64, n int)

ConsumeVarint parses b as a varint-encoded uint64, reporting its length. This returns -1 upon any error, -1 for parse error and -2 for overflow.

func DecodeBytes added in v0.12.0

func DecodeBytes(b []byte, idx int, cp bool) ([]byte, int, error)

DecodeBytes decodes a length-prefixed byte slice. If copy is false, returns a sub-slice. Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.

func DecodeBytesAppend added in v0.15.0

func DecodeBytesAppend(dst []byte, b []byte, idx int) ([]byte, int, error)

DecodeBytesAppend decodes a length-prefixed byte slice into dst and returns the new offset. It preserves generated singular bytes behavior by reusing dst and making empty values non-nil.

func DecodeFixed32 added in v0.12.0

func DecodeFixed32(b []byte, idx int) (uint32, int, error)

DecodeFixed32 decodes a fixed 32-bit value. Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.

func DecodeFixed64 added in v0.12.0

func DecodeFixed64(b []byte, idx int) (uint64, int, error)

DecodeFixed64 decodes a fixed 64-bit value. Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.

func DecodeFloat32 added in v0.12.0

func DecodeFloat32(b []byte, idx int) (float32, int, error)

DecodeFloat32 decodes a 32-bit float. Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.

func DecodeFloat64 added in v0.12.0

func DecodeFloat64(b []byte, idx int) (float64, int, error)

DecodeFloat64 decodes a 64-bit float. Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.

func DecodeLengthDelimited added in v0.15.0

func DecodeLengthDelimited(b []byte, idx int) (int, int, error)

DecodeLengthDelimited decodes a length-delimited payload and returns its start and end offsets. Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.

func DecodeSint32 added in v0.12.0

func DecodeSint32(b []byte, idx int) (int32, int, error)

DecodeSint32 decodes a zigzag-encoded sint32. Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.

func DecodeSint64 added in v0.12.0

func DecodeSint64(b []byte, idx int) (int64, int, error)

DecodeSint64 decodes a zigzag-encoded sint64. Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.

func DecodeString added in v0.12.0

func DecodeString(b []byte, idx int) (string, int, error)

DecodeString decodes a length-prefixed string (with copy). Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.

func DecodeStringUnsafe added in v0.12.0

func DecodeStringUnsafe(b []byte, idx int) (string, int, error)

DecodeStringUnsafe decodes a length-prefixed string without copying. The returned string shares memory with the input slice. Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.

func DecodeVarint added in v0.12.0

func DecodeVarint(b []byte, idx int) (uint64, int, error)

DecodeVarint decodes a varint at the given index, returning value, new index, and error. Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.

func DecodeVarintBool added in v0.12.0

func DecodeVarintBool(b []byte, idx int) (bool, int, error)

DecodeVarintBool decodes a varint as bool. Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.

func DecodeVarintInt32 added in v0.12.0

func DecodeVarintInt32(b []byte, idx int) (int32, int, error)

DecodeVarintInt32 decodes a varint as int32. Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.

func DecodeVarintInt64 added in v0.12.0

func DecodeVarintInt64(b []byte, idx int) (int64, int, error)

DecodeVarintInt64 decodes a varint as int64. Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.

func DecodeVarintUint32 added in v0.12.0

func DecodeVarintUint32(b []byte, idx int) (uint32, int, error)

DecodeVarintUint32 decodes a varint as uint32. Assumes idx is within bounds (0 <= idx <= len(b)); generated code maintains this invariant.

func EncodeBool added in v0.15.0

func EncodeBool(dAtA []byte, offset int, v bool) int

EncodeBool writes a bool value before offset and returns the new offset.

func EncodeBytes added in v0.15.0

func EncodeBytes[S ~[]byte](dAtA []byte, offset int, v S) int

EncodeBytes writes a length-delimited byte slice before offset and returns the new offset.

func EncodeFixed32 added in v0.15.0

func EncodeFixed32(dAtA []byte, offset int, v uint32) int

EncodeFixed32 writes a fixed-width 32-bit value before offset and returns the new offset.

func EncodeFixed64 added in v0.15.0

func EncodeFixed64(dAtA []byte, offset int, v uint64) int

EncodeFixed64 writes a fixed-width 64-bit value before offset and returns the new offset.

func EncodeRawBytes added in v0.15.0

func EncodeRawBytes[S ~[]byte](dAtA []byte, offset int, v S) int

EncodeRawBytes writes raw bytes before offset and returns the new offset.

func EncodeString added in v0.15.0

func EncodeString[S ~string](dAtA []byte, offset int, v S) int

EncodeString writes a length-delimited string before offset and returns the new offset.

func EncodeVarint added in v0.2.5

func EncodeVarint(dAtA []byte, offset int, v uint64) int

EncodeVarint encodes a uint64 into a varint-encoded byte slice and returns the offset of the encoded value. The provided offset is the offset after the last byte of the encoded value.

func EncodeVarintPacked added in v0.15.0

func EncodeVarintPacked[S ~[]E, E marshalVarintNumber](dAtA []byte, offset int, vals S) int

EncodeVarintPacked writes packed varint values before offset and returns the new offset.

func EncodeZigzag32 added in v0.15.0

func EncodeZigzag32[T ~int32](dAtA []byte, offset int, v T) int

EncodeZigzag32 writes a zigzag-encoded 32-bit value before offset and returns the new offset.

func EncodeZigzag32Packed added in v0.15.0

func EncodeZigzag32Packed[S ~[]E, E ~int32](dAtA []byte, offset int, vals S) int

EncodeZigzag32Packed writes packed zigzag-encoded 32-bit values before offset and returns the new offset.

func EncodeZigzag64 added in v0.15.0

func EncodeZigzag64[T ~int64](dAtA []byte, offset int, v T) int

EncodeZigzag64 writes a zigzag-encoded 64-bit value before offset and returns the new offset.

func EncodeZigzag64Packed added in v0.15.0

func EncodeZigzag64Packed[S ~[]E, E ~int64](dAtA []byte, offset int, vals S) int

EncodeZigzag64Packed writes packed zigzag-encoded 64-bit values before offset and returns the new offset.

func EqualBytes added in v0.15.0

func EqualBytes(a, b []byte) bool

EqualBytes compares two implicit bytes values.

func EqualBytesMap added in v0.15.0

func EqualBytesMap[M ~map[K]V, K comparable, V ~[]byte](a, b M) bool

EqualBytesMap compares maps whose values are bytes fields.

func EqualBytesPresent added in v0.15.0

func EqualBytesPresent(a, b []byte) bool

EqualBytesPresent compares two explicit bytes values where nil and empty differ.

func EqualBytesSlice added in v0.15.0

func EqualBytesSlice[S ~[]E, E ~[]byte](a, b S) bool

EqualBytesSlice compares repeated bytes values.

func EqualMap added in v0.15.0

func EqualMap[M ~map[K]V, K comparable, V comparable](a, b M) bool

EqualMap compares maps with comparable values.

func EqualPtr added in v0.15.0

func EqualPtr[T comparable](a, b *T) bool

EqualPtr compares two explicit scalar pointers.

func EqualSlice added in v0.15.0

func EqualSlice[S ~[]E, E comparable](a, b S) bool

EqualSlice compares repeated comparable values.

func EqualVTImplicit added in v0.15.0

func EqualVTImplicit[T EqualVT[T]](a, b T, empty func() T) bool

EqualVTImplicit compares VT messages where nil is equivalent to an empty message.

func EqualVTMapImplicit added in v0.15.0

func EqualVTMapImplicit[M ~map[K]V, K comparable, V EqualVT[V]](a, b M, empty func() V) bool

EqualVTMapImplicit compares map VT values where nil values are empty messages.

func EqualVTSliceImplicit added in v0.15.0

func EqualVTSliceImplicit[S ~[]E, E EqualVT[E]](a, b S, empty func() E) bool

EqualVTSliceImplicit compares repeated VT messages where nil elements are empty messages.

func IsEqualVT

func IsEqualVT[T EqualVT[T]](t1, t2 T) bool

IsEqualVT checks if two EqualVT objects are equal.

func IsEqualVTSlice added in v0.6.2

func IsEqualVTSlice[S ~[]E, E EqualVT[E]](s1, s2 S) bool

IsEqualVTSlice checks if two slices of EqualVT messages are equal.

func PackedFixedElementCount added in v0.15.0

func PackedFixedElementCount(b []byte, width int) int

PackedFixedElementCount returns the number of fixed-width elements in a packed payload.

func PackedVarintElementCount added in v0.15.0

func PackedVarintElementCount(b []byte) (n int)

PackedVarintElementCount returns the number of varint elements in a packed payload.

func SizeBoolNonZero added in v0.15.0

func SizeBoolNonZero(keySize int, v bool) int

SizeBoolNonZero returns the encoded field size for one implicit bool value.

func SizeBoolPacked added in v0.15.0

func SizeBoolPacked(keySize int, vals []bool) int

SizeBoolPacked returns the encoded field size for packed repeated bool values.

func SizeBoolPtr added in v0.15.0

func SizeBoolPtr(keySize int, v *bool) int

SizeBoolPtr returns the encoded field size for one explicit bool value.

func SizeBoolSlice added in v0.15.0

func SizeBoolSlice(keySize int, vals []bool) int

SizeBoolSlice returns the encoded field size for unpacked repeated bool values.

func SizeBoolValue added in v0.15.0

func SizeBoolValue(keySize int) int

SizeBoolValue returns the encoded field size for one present bool value.

func SizeBytesNonEmpty added in v0.15.0

func SizeBytesNonEmpty(keySize int, v []byte) int

SizeBytesNonEmpty returns the encoded field size for one implicit bytes value.

func SizeBytesPresent added in v0.15.0

func SizeBytesPresent(keySize int, v []byte) int

SizeBytesPresent returns the encoded field size for one explicit bytes value.

func SizeBytesSlice added in v0.15.0

func SizeBytesSlice[S ~[]E, E ~[]byte](keySize int, vals S) (n int)

SizeBytesSlice returns the encoded field size for repeated bytes values.

func SizeBytesValue added in v0.15.0

func SizeBytesValue(keySize, l int) int

SizeBytesValue returns the encoded field size for one present length-delimited value.

func SizeFixed32NonZero added in v0.15.0

func SizeFixed32NonZero[T sizeFixed32Number](keySize int, v T) int

SizeFixed32NonZero returns the encoded field size for one implicit fixed32 value.

func SizeFixed32Packed added in v0.15.0

func SizeFixed32Packed[S ~[]E, E sizeFixed32Number](keySize int, vals S) int

SizeFixed32Packed returns the encoded field size for packed repeated fixed32 values.

func SizeFixed32Ptr added in v0.15.0

func SizeFixed32Ptr[T sizeFixed32Number](keySize int, v *T) int

SizeFixed32Ptr returns the encoded field size for one explicit fixed32 value.

func SizeFixed32Slice added in v0.15.0

func SizeFixed32Slice[S ~[]E, E sizeFixed32Number](keySize int, vals S) int

SizeFixed32Slice returns the encoded field size for unpacked repeated fixed32 values.

func SizeFixed32Value added in v0.15.0

func SizeFixed32Value(keySize int) int

SizeFixed32Value returns the encoded field size for one present fixed32 value.

func SizeFixed64NonZero added in v0.15.0

func SizeFixed64NonZero[T sizeFixed64Number](keySize int, v T) int

SizeFixed64NonZero returns the encoded field size for one implicit fixed64 value.

func SizeFixed64Packed added in v0.15.0

func SizeFixed64Packed[S ~[]E, E sizeFixed64Number](keySize int, vals S) int

SizeFixed64Packed returns the encoded field size for packed repeated fixed64 values.

func SizeFixed64Ptr added in v0.15.0

func SizeFixed64Ptr[T sizeFixed64Number](keySize int, v *T) int

SizeFixed64Ptr returns the encoded field size for one explicit fixed64 value.

func SizeFixed64Slice added in v0.15.0

func SizeFixed64Slice[S ~[]E, E sizeFixed64Number](keySize int, vals S) int

SizeFixed64Slice returns the encoded field size for unpacked repeated fixed64 values.

func SizeFixed64Value added in v0.15.0

func SizeFixed64Value(keySize int) int

SizeFixed64Value returns the encoded field size for one present fixed64 value.

func SizeGroup added in v0.15.0

func SizeGroup(keySize, msgSize int) int

SizeGroup returns the encoded field size for one group value.

func SizeMessage added in v0.15.0

func SizeMessage(keySize, msgSize int) int

SizeMessage returns the encoded field size for one length-delimited message or map entry.

func SizeOfVarint added in v0.2.5

func SizeOfVarint(x uint64) (n int)

SizeOfVarint returns the size of the varint-encoded value.

func SizeOfZigzag added in v0.2.5

func SizeOfZigzag(x uint64) (n int)

SizeOfZigzag returns the size of the zigzag-encoded value.

func SizeStringNonEmpty added in v0.15.0

func SizeStringNonEmpty(keySize int, v string) int

SizeStringNonEmpty returns the encoded field size for one implicit string value.

func SizeStringPtr added in v0.15.0

func SizeStringPtr(keySize int, v *string) int

SizeStringPtr returns the encoded field size for one explicit string value.

func SizeStringSlice added in v0.15.0

func SizeStringSlice[S ~[]E, E ~string](keySize int, vals S) (n int)

SizeStringSlice returns the encoded field size for repeated strings.

func SizeStringValue added in v0.15.0

func SizeStringValue(keySize int, v string) int

SizeStringValue returns the encoded field size for one present string value.

func SizeVarintNonZero added in v0.15.0

func SizeVarintNonZero[T sizeVarintNumber](keySize int, v T) int

SizeVarintNonZero returns the encoded field size for one implicit varint value.

func SizeVarintPacked added in v0.15.0

func SizeVarintPacked[S ~[]E, E sizeVarintNumber](keySize int, vals S) int

SizeVarintPacked returns the encoded field size for packed repeated varints.

func SizeVarintPtr added in v0.15.0

func SizeVarintPtr[T sizeVarintNumber](keySize int, v *T) int

SizeVarintPtr returns the encoded field size for one explicit varint value.

func SizeVarintSlice added in v0.15.0

func SizeVarintSlice[S ~[]E, E sizeVarintNumber](keySize int, vals S) (n int)

SizeVarintSlice returns the encoded field size for unpacked repeated varints.

func SizeVarintValue added in v0.15.0

func SizeVarintValue[T sizeVarintNumber](keySize int, v T) int

SizeVarintValue returns the encoded field size for one present varint value.

func SizeZigzagNonZero added in v0.15.0

func SizeZigzagNonZero[T sizeZigzagNumber](keySize int, v T) int

SizeZigzagNonZero returns the encoded field size for one implicit zigzag value.

func SizeZigzagPacked added in v0.15.0

func SizeZigzagPacked[S ~[]E, E sizeZigzagNumber](keySize int, vals S) int

SizeZigzagPacked returns the encoded field size for packed repeated zigzags.

func SizeZigzagPtr added in v0.15.0

func SizeZigzagPtr[T sizeZigzagNumber](keySize int, v *T) int

SizeZigzagPtr returns the encoded field size for one explicit zigzag value.

func SizeZigzagSlice added in v0.15.0

func SizeZigzagSlice[S ~[]E, E sizeZigzagNumber](keySize int, vals S) (n int)

SizeZigzagSlice returns the encoded field size for unpacked repeated zigzags.

func SizeZigzagValue added in v0.15.0

func SizeZigzagValue[T sizeZigzagNumber](keySize int, v T) int

SizeZigzagValue returns the encoded field size for one present zigzag value.

func Skip added in v0.2.5

func Skip(dAtA []byte) (n int, err error)

Skip the first record of the byte slice and return the offset of the next record.

func SkipWithin added in v0.15.0

func SkipWithin(dAtA []byte, idx, limit int) (int, error)

SkipWithin skips one encoded field at idx and verifies it stays within limit.

func TextFinishMessage added in v0.15.0

func TextFinishMessage(sb *TextBuilder) string

TextFinishMessage writes the closing message delimiter and returns the final text.

func TextSortedMapKeys added in v0.15.0

func TextSortedMapKeys[M ~map[K]V, K cmp.Ordered, V any](m M) []K

TextSortedMapKeys returns sorted keys for deterministic generated proto text maps.

func TextStartMessage added in v0.15.0

func TextStartMessage(sb *TextBuilder, name string) int

TextStartMessage writes the opening message label and returns its initial length.

func TextWriteBool added in v0.15.0

func TextWriteBool(sb *TextBuilder, v bool)

TextWriteBool writes a bool proto text value.

func TextWriteBytes added in v0.15.0

func TextWriteBytes[B ~[]byte](sb *TextBuilder, v B)

TextWriteBytes writes a quoted base64 proto text bytes value.

func TextWriteFieldPrefix added in v0.15.0

func TextWriteFieldPrefix(sb *TextBuilder, initialLen int, name string)

TextWriteFieldPrefix writes the optional separator, field name, and value separator.

func TextWriteFloat32 added in v0.15.0

func TextWriteFloat32(sb *TextBuilder, v float32)

TextWriteFloat32 writes a float32 proto text value.

func TextWriteFloat64 added in v0.15.0

func TextWriteFloat64(sb *TextBuilder, v float64)

TextWriteFloat64 writes a float64 proto text value.

func TextWriteInt added in v0.15.0

func TextWriteInt[T ~int32 | ~int64](sb *TextBuilder, v T)

TextWriteInt writes a signed integer proto text value.

func TextWriteListEnd added in v0.15.0

func TextWriteListEnd(sb *TextBuilder)

TextWriteListEnd writes the repeated field closing delimiter.

func TextWriteListSeparator added in v0.15.0

func TextWriteListSeparator(sb *TextBuilder, index int)

TextWriteListSeparator writes the separator before non-first repeated values.

func TextWriteListStart added in v0.15.0

func TextWriteListStart(sb *TextBuilder, initialLen int, name string)

TextWriteListStart writes a repeated field prefix and opening delimiter.

func TextWriteMapEnd added in v0.15.0

func TextWriteMapEnd(sb *TextBuilder)

TextWriteMapEnd writes the map field closing delimiter.

func TextWriteMapEntryPrefix added in v0.15.0

func TextWriteMapEntryPrefix(sb *TextBuilder)

TextWriteMapEntryPrefix writes the separator before one sorted map entry.

func TextWriteMapKeyValueSeparator added in v0.15.0

func TextWriteMapKeyValueSeparator(sb *TextBuilder)

TextWriteMapKeyValueSeparator writes the separator between a map key and value.

func TextWriteMapStart added in v0.15.0

func TextWriteMapStart(sb *TextBuilder, initialLen int, name string)

TextWriteMapStart writes a map field prefix and opening delimiter.

func TextWriteString added in v0.15.0

func TextWriteString(sb *TextBuilder, v string)

TextWriteString writes a quoted string proto text value.

func TextWriteStringer added in v0.15.0

func TextWriteStringer[T interface{ String() string }](sb *TextBuilder, v T)

TextWriteStringer writes a quoted String value.

func TextWriteTextMarshaler added in v0.15.0

func TextWriteTextMarshaler(sb *TextBuilder, v TextMarshaler)

TextWriteTextMarshaler writes a nested proto text marshaler value.

func TextWriteUint added in v0.15.0

func TextWriteUint[T ~uint32 | ~uint64](sb *TextBuilder, v T)

TextWriteUint writes an unsigned integer proto text value.

Types

type CloneMessage added in v0.4.8

type CloneMessage interface {
	// Message extends the base message type.
	Message
	// CloneMessageVT clones the object.
	CloneMessageVT() CloneMessage
}

CloneMessage is a message with a CloneMessage function.

type CloneVT added in v0.4.8

type CloneVT[T comparable] interface {
	comparable
	// CloneMessage is the non-generic clone interface.
	CloneMessage
	// CloneVT clones the object.
	CloneVT() T
}

CloneVT is a message with a CloneVT function (VTProtobuf).

type EqualVT

type EqualVT[T comparable] interface {
	comparable
	// EqualVT compares against the other message for equality.
	EqualVT(other T) bool
}

EqualVT is a message with a EqualVT function (VTProtobuf).

type JSONMessage added in v0.9.0

type JSONMessage interface {
	// MarshalJSON marshals the message to JSON.
	MarshalJSON() ([]byte, error)
	// UnmarshalJSON unmarshals the message from JSON.
	UnmarshalJSON(data []byte) error
}

JSONMessage is a message with MarshalJSON and UnmarshalJSON.

type Message

type Message interface {
	// SizeVT returns the size of the message when marshaled.
	SizeVT() int
	// MarshalToSizedBufferVT marshals to a buffer that already is SizeVT bytes long.
	MarshalToSizedBufferVT(dAtA []byte) (int, error)
	// MarshalVT marshals the message with vtprotobuf.
	MarshalVT() ([]byte, error)
	// UnmarshalVT unmarshals the message object with vtprotobuf.
	UnmarshalVT(data []byte) error
	// Reset resets the message.
	Reset()
}

Message is the base vtprotobuf message marshal/unmarshal interface.

type TextBuilder added in v0.15.0

type TextBuilder = strings.Builder

TextBuilder is the builder used by generated proto text marshalers.

type TextMarshaler added in v0.15.0

type TextMarshaler interface {
	MarshalProtoText() string
}

TextMarshaler is a message with a MarshalProtoText function.

Directories

Path Synopsis
cmd
protoc-gen-go-lite command
The protoc-gen-go-lite binary is a protoc plugin to generate Go code for both proto2 and proto3 versions of the protocol buffer language.
The protoc-gen-go-lite binary is a protoc plugin to generate Go code for both proto2 and proto3 versions of the protocol buffer language.
compiler
protogen
Package protogen provides support for writing protoc plugins.
Package protogen provides support for writing protoc plugins.
protogenlite
Package protogenlite provides a minimal protoc plugin model for generators that only need file/service/method metadata and Go import qualification.
Package protogenlite provides a minimal protoc plugin model for generators that only need file/service/method metadata and Go import qualification.
encoding
protowire
Package protowire parses and formats the raw wire encoding.
Package protowire parses and formats the raw wire encoding.
features
fieldsem
Package fieldsem resolves protobuf descriptors to generated Go field representation semantics.
Package fieldsem resolves protobuf descriptors to generated Go field representation semantics.
internal
detrand
Package detrand provides deterministically random functionality.
Package detrand provides deterministically random functionality.
editiondefaults
Package editiondefaults contains the binary representation of the editions defaults.
Package editiondefaults contains the binary representation of the editions defaults.
editionssupport
Package editionssupport defines constants for editions that are supported.
Package editionssupport defines constants for editions that are supported.
encoding/defval
Package defval marshals and unmarshals textual forms of default values.
Package defval marshals and unmarshals textual forms of default values.
encoding/tag
Package tag marshals and unmarshals the legacy struct tags as generated by historical versions of protoc-gen-go.
Package tag marshals and unmarshals the legacy struct tags as generated by historical versions of protoc-gen-go.
encoding/text
Package text implements the text format for protocol buffers.
Package text implements the text format for protocol buffers.
errors
Package errors implements functions to manipulate errors.
Package errors implements functions to manipulate errors.
genid
Package genid contains constants for declarations in descriptor.proto and the well-known types.
Package genid contains constants for declarations in descriptor.proto and the well-known types.
order
Package order provides ordered access to messages and maps.
Package order provides ordered access to messages and maps.
pragma
Package pragma provides types that can be embedded into a struct to statically enforce or prevent certain language properties.
Package pragma provides types that can be embedded into a struct to statically enforce or prevent certain language properties.
protobuild
Package protobuild constructs messages.
Package protobuild constructs messages.
set
Package set provides simple set data structures for uint64s.
Package set provides simple set data structures for uint64s.
strs
Package strs provides string manipulation functionality specific to protobuf.
Package strs provides string manipulation functionality specific to protobuf.
version
Package version records versioning information about this module.
Package version records versioning information about this module.
weakdeps
Package weakdeps exists to add weak module dependencies.
Package weakdeps exists to add weak module dependencies.
testproto
wkt
types

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL