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(value uint32) []byte
EncodeFixed32 encodes a uint32 into 4 bytes (little-endian).
func EncodeFixed64(value uint64) []byte
EncodeFixed64 encodes a uint64 into 8 bytes (little-endian).
func EncodeVarint(value uint64) []byte
EncodeVarint encodes a uint64 into varint bytes.
func ParseFixed32(buffer []byte) (uint32, int, error)
ParseFixed32 parses a 32-bit little-endian integer from the buffer.
func ParseFixed64(buffer []byte) (uint64, int, error)
ParseFixed64 parses a 64-bit little-endian integer from the buffer.
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.
Field represents a single, decoded field in a protobuf message.
type Field struct { Tag Tag Numeric uint64 Bytes []byte Message Message }
func Bytes(fieldNum uint32, value []byte) *Field
Bytes creates a new Bytes field and returns a pointer to it.
func Embed(fieldNum uint32, value ...*Field) *Field
Embed creates a new embedded message field from the provided sub-fields.
func Fixed32(fieldNum uint32, value uint32) *Field
Fixed32 creates a new Fixed32 field and returns a pointer to it.
func Fixed64(fieldNum uint32, value uint64) *Field
Fixed64 creates a new Fixed64 field and returns a pointer to it.
func String(fieldNum uint32, value string) *Field
String creates a new String (WireBytes) field and returns a pointer to it.
func Varint(fieldNum uint32, value uint64) *Field
Varint creates a new Varint field and returns a pointer to it.
Iterator provides a stateful, memory-efficient way to loop over all occurrences of a specific field number within a message.
type Iterator struct { // contains filtered or unexported fields }
func (it *Iterator) Field() *Field
Field returns a pointer to the current field the iterator is pointing to.
func (it *Iterator) Next() bool
Next advances the iterator to the next matching field. It returns false when there are no more matching fields.
Message is a named type for a slice of field pointers, representing a parsed protobuf message.
type Message []*Field
func (m Message) Encode() ([]byte, error)
Encode serializes the message into the protobuf wire format.
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 (m Message) Iterator(fieldNum uint32) *Iterator
Iterator creates a new iterator to loop over all fields with the given number.
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.
Tag represents a field's tag (Field Number + Wire Type).
type Tag struct { Number uint32 Type Type }
func ParseTag(buffer []byte) (Tag, int, error)
ParseTag decodes a varint from the input buffer and returns it as a Tag struct.
Type represents the type of data encoding on the wire.
type Type uint8