runtime

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package runtime provides low-level protobuf wire format encoding primitives. Generated MarshalBinary/UnmarshalBinary code calls this package directly, with no dependency on the official protobuf reflection mechanism.

Package runtime provides low-level protobuf wire format encoding primitives. Generated marshal/unmarshal code calls these functions directly.

Index

Constants

View Source
const (
	WireVarint  = 0
	WireFixed64 = 1
	WireBytes   = 2
	WireFixed32 = 5
)

Wire type constants.

View Source
const DefaultRecursionLimit = 100

DefaultRecursionLimit is the maximum message nesting depth allowed during unmarshal. Generated UnmarshalBinary / UnmarshalBinaryLenient start with this budget and decrement it on each nested message call. 100 is sufficient for any realistic business schema; deeply nested messages indicate a design problem and are rejected early to prevent stack exhaustion.

Variables

View Source
var ErrDuplicateField = errorString("protobuf: duplicate non-repeated field")

ErrDuplicateField is returned when a non-repeated field appears more than once.

View Source
var ErrNestingDepth = errorString("protobuf: message nesting depth exceeded")

ErrNestingDepth is returned when message nesting exceeds DefaultRecursionLimit.

View Source
var ErrOverflow = errorString("protobuf: varint overflow")

ErrOverflow is returned when a varint overflows 64 bits.

View Source
var ErrPackedLen = errorString("protobuf: packed field length mismatch")

ErrPackedLen is returned when a packed field payload length is not a multiple of element size.

View Source
var ErrTruncated = errorString("protobuf: truncated message")

ErrTruncated is returned when the input buffer ends unexpectedly.

View Source
var ErrUnknownWireType = errorString("protobuf: unknown wire type")

ErrUnknownWireType is returned when SkipField encounters an unrecognized wire type. Wire types 0-5 are defined by the protobuf spec; any other value is invalid.

View Source
var ErrWireType = errorString("protobuf: wrong wire type")

ErrWireType is returned when a field's wire type does not match the expected type.

Functions

func AppendBool

func AppendBool(b []byte, v bool) []byte

AppendBool appends a bool as a single-byte varint (0 or 1).

func AppendBytes

func AppendBytes(b []byte, v []byte) []byte

AppendBytes appends a length-delimited byte slice.

func AppendDouble

func AppendDouble(b []byte, v float64) []byte

AppendDouble appends a float64 as fixed64.

func AppendFixed32

func AppendFixed32(b []byte, v uint32) []byte

AppendFixed32 appends a 4-byte little-endian value.

func AppendFixed64

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

AppendFixed64 appends an 8-byte little-endian value.

func AppendFloat

func AppendFloat(b []byte, v float32) []byte

AppendFloat appends a float32 as fixed32.

func AppendSint32

func AppendSint32(b []byte, v int32) []byte

AppendSint32 appends a ZigZag-encoded sint32 as a varint.

func AppendSint64

func AppendSint64(b []byte, v int64) []byte

AppendSint64 appends a ZigZag-encoded sint64 as a varint.

func AppendString

func AppendString(b []byte, v string) []byte

AppendString appends a length-delimited string.

func AppendTag

func AppendTag(b []byte, fieldNumber int, wireType int) []byte

AppendTag appends a protobuf field tag (field_number << 3 | wire_type).

func AppendVarint

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

AppendVarint appends a base-128 varint-encoded uint64.

func ConsumeBytes

func ConsumeBytes(b []byte) ([]byte, int)

ConsumeBytes reads a length-delimited byte slice from b. Returns (nil, -1) if truncated, (nil, -2) if length overflows.

func ConsumeFixed32

func ConsumeFixed32(b []byte) (uint32, int)

ConsumeFixed32 reads 4 bytes little-endian from b. Returns (0, -1) if the buffer is too short.

func ConsumeFixed64

func ConsumeFixed64(b []byte) (uint64, int)

ConsumeFixed64 reads 8 bytes little-endian from b. Returns (0, -1) if the buffer is too short.

func ConsumeTag

func ConsumeTag(b []byte) (int, int, int)

ConsumeTag reads a field tag from b, returning (fieldNumber, wireType, bytesConsumed). Returns (-1, -1, n<0) on error.

func ConsumeVarint

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

ConsumeVarint reads a varint from b, returning the value and bytes consumed. Returns (0, -1) if the buffer is too short, (0, -2) if the varint overflows.

func DecodeZigZag32

func DecodeZigZag32(v uint64) int32

DecodeZigZag32 decodes a ZigZag-encoded uint64 back to int32.

func DecodeZigZag64

func DecodeZigZag64(v uint64) int64

DecodeZigZag64 decodes a ZigZag-encoded uint64 back to int64.

func EncodeZigZag32

func EncodeZigZag32(v int32) uint64

EncodeZigZag32 encodes a signed int32 using ZigZag encoding.

func EncodeZigZag64

func EncodeZigZag64(v int64) uint64

EncodeZigZag64 encodes a signed int64 using ZigZag encoding.

func IsZeroDouble

func IsZeroDouble(v float64) bool

IsZeroDouble returns true if v is positive zero.

func IsZeroFloat

func IsZeroFloat(v float32) bool

IsZeroFloat returns true if v is positive zero.

func SizeBool

func SizeBool(_ bool) int

SizeBool returns the wire size of a bool field value (always 1).

func SizeBytes

func SizeBytes(v []byte) int

SizeBytes returns the wire size of a length-delimited byte slice.

func SizeDouble

func SizeDouble(_ float64) int

SizeDouble returns the wire size of a double (always 8).

func SizeEnum

func SizeEnum(v int32) int

SizeEnum returns the varint-encoded size of an enum value (int32).

func SizeFixed32

func SizeFixed32(_ uint32) int

SizeFixed32 returns the wire size of a fixed32 (always 4).

func SizeFixed64

func SizeFixed64(_ uint64) int

SizeFixed64 returns the wire size of a fixed64 (always 8).

func SizeFloat

func SizeFloat(_ float32) int

SizeFloat returns the wire size of a float (always 4).

func SizeInt32

func SizeInt32(v int32) int

SizeInt32 returns the varint-encoded size of an int32. Negative values are sign-extended to 10 bytes.

func SizeInt64

func SizeInt64(v int64) int

SizeInt64 returns the varint-encoded size of an int64.

func SizeSfixed32

func SizeSfixed32(_ int32) int

SizeSfixed32 returns the wire size of an sfixed32 (always 4).

func SizeSfixed64

func SizeSfixed64(_ int64) int

SizeSfixed64 returns the wire size of an sfixed64 (always 8).

func SizeSint32

func SizeSint32(v int32) int

SizeSint32 returns the varint-encoded size of a ZigZag-encoded sint32.

func SizeSint64

func SizeSint64(v int64) int

SizeSint64 returns the varint-encoded size of a ZigZag-encoded sint64.

func SizeString

func SizeString(v string) int

SizeString returns the wire size of a length-delimited string (length prefix + content).

func SizeTag

func SizeTag(fieldNumber int) int

SizeTag returns the number of bytes needed to encode a field tag.

func SizeUint32

func SizeUint32(v uint32) int

SizeUint32 returns the varint-encoded size of a uint32.

func SizeUint64

func SizeUint64(v uint64) int

SizeUint64 returns the varint-encoded size of a uint64.

func SizeVarint

func SizeVarint(v uint64) int

SizeVarint returns the number of bytes needed to varint-encode v.

func SkipField

func SkipField(b []byte, wireType int) int

SkipField skips a field value given its wire type. Returns the number of bytes consumed, or a negative error code: -1 for truncated input, -3 for an unrecognized wire type.

Types

This section is empty.

Jump to

Keyboard shortcuts

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