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
- Variables
- func AppendBool(b []byte, v bool) []byte
- func AppendBytes(b []byte, v []byte) []byte
- func AppendDouble(b []byte, v float64) []byte
- func AppendFixed32(b []byte, v uint32) []byte
- func AppendFixed64(b []byte, v uint64) []byte
- func AppendFloat(b []byte, v float32) []byte
- func AppendSint32(b []byte, v int32) []byte
- func AppendSint64(b []byte, v int64) []byte
- func AppendString(b []byte, v string) []byte
- func AppendTag(b []byte, fieldNumber int, wireType int) []byte
- func AppendVarint(b []byte, v uint64) []byte
- func ConsumeBytes(b []byte) ([]byte, int)
- func ConsumeFixed32(b []byte) (uint32, int)
- func ConsumeFixed64(b []byte) (uint64, int)
- func ConsumeTag(b []byte) (int, int, int)
- func ConsumeVarint(b []byte) (uint64, int)
- func DecodeZigZag32(v uint64) int32
- func DecodeZigZag64(v uint64) int64
- func EncodeZigZag32(v int32) uint64
- func EncodeZigZag64(v int64) uint64
- func IsZeroDouble(v float64) bool
- func IsZeroFloat(v float32) bool
- func SizeBool(_ bool) int
- func SizeBytes(v []byte) int
- func SizeDouble(_ float64) int
- func SizeEnum(v int32) int
- func SizeFixed32(_ uint32) int
- func SizeFixed64(_ uint64) int
- func SizeFloat(_ float32) int
- func SizeInt32(v int32) int
- func SizeInt64(v int64) int
- func SizeSfixed32(_ int32) int
- func SizeSfixed64(_ int64) int
- func SizeSint32(v int32) int
- func SizeSint64(v int64) int
- func SizeString(v string) int
- func SizeTag(fieldNumber int) int
- func SizeUint32(v uint32) int
- func SizeUint64(v uint64) int
- func SizeVarint(v uint64) int
- func SkipField(b []byte, wireType int) int
Constants ¶
const ( WireVarint = 0 WireFixed64 = 1 WireBytes = 2 WireFixed32 = 5 )
Wire type constants.
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 ¶
var ErrDuplicateField = errorString("protobuf: duplicate non-repeated field")
ErrDuplicateField is returned when a non-repeated field appears more than once.
var ErrNestingDepth = errorString("protobuf: message nesting depth exceeded")
ErrNestingDepth is returned when message nesting exceeds DefaultRecursionLimit.
var ErrOverflow = errorString("protobuf: varint overflow")
ErrOverflow is returned when a varint overflows 64 bits.
var ErrPackedLen = errorString("protobuf: packed field length mismatch")
ErrPackedLen is returned when a packed field payload length is not a multiple of element size.
var ErrTruncated = errorString("protobuf: truncated message")
ErrTruncated is returned when the input buffer ends unexpectedly.
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.
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 ¶
AppendBool appends a bool as a single-byte varint (0 or 1).
func AppendBytes ¶
AppendBytes appends a length-delimited byte slice.
func AppendDouble ¶
AppendDouble appends a float64 as fixed64.
func AppendFixed32 ¶
AppendFixed32 appends a 4-byte little-endian value.
func AppendFixed64 ¶
AppendFixed64 appends an 8-byte little-endian value.
func AppendFloat ¶
AppendFloat appends a float32 as fixed32.
func AppendSint32 ¶
AppendSint32 appends a ZigZag-encoded sint32 as a varint.
func AppendSint64 ¶
AppendSint64 appends a ZigZag-encoded sint64 as a varint.
func AppendString ¶
AppendString appends a length-delimited string.
func AppendVarint ¶
AppendVarint appends a base-128 varint-encoded uint64.
func ConsumeBytes ¶
ConsumeBytes reads a length-delimited byte slice from b. Returns (nil, -1) if truncated, (nil, -2) if length overflows.
func ConsumeFixed32 ¶
ConsumeFixed32 reads 4 bytes little-endian from b. Returns (0, -1) if the buffer is too short.
func ConsumeFixed64 ¶
ConsumeFixed64 reads 8 bytes little-endian from b. Returns (0, -1) if the buffer is too short.
func ConsumeTag ¶
ConsumeTag reads a field tag from b, returning (fieldNumber, wireType, bytesConsumed). Returns (-1, -1, n<0) on error.
func ConsumeVarint ¶
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 ¶
DecodeZigZag32 decodes a ZigZag-encoded uint64 back to int32.
func DecodeZigZag64 ¶
DecodeZigZag64 decodes a ZigZag-encoded uint64 back to int64.
func EncodeZigZag32 ¶
EncodeZigZag32 encodes a signed int32 using ZigZag encoding.
func EncodeZigZag64 ¶
EncodeZigZag64 encodes a signed int64 using ZigZag encoding.
func IsZeroDouble ¶
IsZeroDouble returns true if v is positive zero.
func SizeDouble ¶
SizeDouble returns the wire size of a double (always 8).
func SizeFixed32 ¶
SizeFixed32 returns the wire size of a fixed32 (always 4).
func SizeFixed64 ¶
SizeFixed64 returns the wire size of a fixed64 (always 8).
func SizeInt32 ¶
SizeInt32 returns the varint-encoded size of an int32. Negative values are sign-extended to 10 bytes.
func SizeSfixed32 ¶
SizeSfixed32 returns the wire size of an sfixed32 (always 4).
func SizeSfixed64 ¶
SizeSfixed64 returns the wire size of an sfixed64 (always 8).
func SizeSint32 ¶
SizeSint32 returns the varint-encoded size of a ZigZag-encoded sint32.
func SizeSint64 ¶
SizeSint64 returns the varint-encoded size of a ZigZag-encoded sint64.
func SizeString ¶
SizeString returns the wire size of a length-delimited string (length prefix + content).
func SizeUint32 ¶
SizeUint32 returns the varint-encoded size of a uint32.
func SizeUint64 ¶
SizeUint64 returns the varint-encoded size of a uint64.
func SizeVarint ¶
SizeVarint returns the number of bytes needed to varint-encode v.
Types ¶
This section is empty.