protobuf

package module
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: OSL-3.0 Imports: 5 Imported by: 4

README

ProtoBuf

In the name of the warrior, I charge you to be brave.
In the name of the father, I charge you to be just.
In the name of the mother, I charge you to defend the innocent.

A Knight of the Seven Kingdoms (Game of Thrones) (2019)

Protocol Buffers

This module parses and formats the raw wire encoding.

prior art

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeVarint added in v1.5.2

func DecodeVarint(buffer []byte) (uint64, int)

DecodeVarint reads a varint from the buffer and returns the decoded uint64 and the number of bytes read. A negative number of bytes indicates an overflow. A zero indicates an unterminated varint.

func EncodeFixed32 added in v1.5.2

func EncodeFixed32(value uint32) []byte

EncodeFixed32 encodes a uint32 into 4 bytes (little-endian).

func EncodeFixed64 added in v1.5.2

func EncodeFixed64(value uint64) []byte

EncodeFixed64 encodes a uint64 into 8 bytes (little-endian).

func EncodeVarint added in v1.5.2

func EncodeVarint(value uint64) []byte

EncodeVarint encodes a uint64 into varint bytes.

func ParseFixed32 added in v1.5.2

func ParseFixed32(buffer []byte) (uint32, int, error)

ParseFixed32 parses a 32-bit little-endian integer from the buffer.

func ParseFixed64 added in v1.5.2

func ParseFixed64(buffer []byte) (uint64, int, error)

ParseFixed64 parses a 64-bit little-endian integer from the buffer.

func ParseLengthPrefixed added in v1.5.2

func ParseLengthPrefixed(buffer []byte) (uint64, int, error)

ParseLengthPrefixed parses a length-prefixed field from the buffer. It returns the length of the data, the number of bytes read for the length header, and an error if any.

Types

type Field added in v1.4.5

type Field struct {
	Tag     Tag
	Numeric uint64
	Bytes   []byte
	Message Message
}

Field represents a single, decoded field in a protobuf message.

func Bytes

func Bytes(fieldNum uint32, value []byte) *Field

Bytes creates a new Bytes field and returns a pointer to it.

func Embed added in v1.5.6

func Embed(fieldNum uint32, value ...*Field) *Field

Embed creates a new embedded message field from the provided sub-fields.

func Fixed32

func Fixed32(fieldNum uint32, value uint32) *Field

Fixed32 creates a new Fixed32 field and returns a pointer to it.

func Fixed64

func Fixed64(fieldNum uint32, value uint64) *Field

Fixed64 creates a new Fixed64 field and returns a pointer to it.

func String added in v1.4.8

func String(fieldNum uint32, value string) *Field

String creates a new String (WireBytes) field and returns a pointer to it.

func Varint

func Varint(fieldNum uint32, value uint64) *Field

Varint creates a new Varint field and returns a pointer to it.

type Iterator added in v1.5.2

type Iterator struct {
	// contains filtered or unexported fields
}

Iterator provides a stateful, memory-efficient way to loop over all occurrences of a specific field number within a message.

func (*Iterator) Field added in v1.5.2

func (it *Iterator) Field() *Field

Field returns a pointer to the current field the iterator is pointing to.

func (*Iterator) Next added in v1.5.2

func (it *Iterator) Next() bool

Next advances the iterator to the next matching field. It returns false when there are no more matching fields.

type Message

type Message []*Field

Message is a named type for a slice of field pointers, representing a parsed protobuf message.

func (Message) Encode added in v1.5.2

func (m Message) Encode() ([]byte, error)

Encode serializes the message into the protobuf wire format.

func (Message) Field added in v1.5.2

func (m Message) Field(fieldNum uint32) (*Field, bool)

Field finds and returns the first field matching the given field number. The boolean return value is false if no matching field is found.

func (Message) Iterator added in v1.5.2

func (m Message) Iterator(fieldNum uint32) *Iterator

Iterator creates a new iterator to loop over all fields with the given number.

func (*Message) Parse added in v1.5.4

func (m *Message) Parse(data []byte) error

Parse populates the message by parsing the protobuf wire format data. It will overwrite any existing fields in the message.

type Tag added in v1.5.2

type Tag struct {
	Number uint32
	Type   Type
}

Tag represents a field's tag (Field Number + Wire Type).

func ParseTag added in v1.5.2

func ParseTag(buffer []byte) (Tag, int, error)

ParseTag decodes a varint from the input buffer and returns it as a Tag struct.

type Type added in v1.5.8

type Type uint8

Type represents the type of data encoding on the wire.

const (
	WireVarint     Type = 0
	WireFixed64    Type = 1
	WireBytes      Type = 2
	WireStartGroup Type = 3 // Deprecated
	WireEndGroup   Type = 4 // Deprecated
	WireFixed32    Type = 5
)

Jump to

Keyboard shortcuts

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