func DecodeVarint(buf []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(v uint32) []byte
EncodeFixed32 encodes a uint32 into 4 bytes (little-endian).
func EncodeFixed64(v uint64) []byte
EncodeFixed64 encodes a uint64 into 8 bytes (little-endian).
func EncodeVarint(v uint64) []byte
EncodeVarint encodes a uint64 into varint bytes.
func ParseFixed32(buf []byte) (uint32, int, error)
ParseFixed32 parses a 32-bit little-endian integer from the buffer.
func ParseFixed64(buf []byte) (uint64, int, error)
ParseFixed64 parses a 64-bit little-endian integer from the buffer.
func ParseLengthPrefixed(buf []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, and an error if any.
func ParseVarint(buf []byte) (uint64, int, error)
ParseVarint parses a varint from the buffer.
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 and returns a pointer to it.
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. It is created by calling the Iterator() method on 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. Call this after Next() returns true.
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 is a convenience method that 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 is the entry point for iterating over fields. It creates a new iterator to loop over all fields with the given number. This is ideal for handling repeated fields.
func (m *Message) Parse(buf []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.
type Tag struct { Number uint32 Type Type }
func ParseTag(buf []byte) (Tag, int, error)
ParseTag decodes a varint from the input buffer and returns it as a Tag.
Type represents the type of data encoding on the wire.
type Type uint8