codec

package
v2.31.9 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package codec implements the wire format for agent <-> boundary communication.

Wire Format:

  • 8 bits: big-endian tag
  • 24 bits: big-endian length of the protobuf data (bit usage depends on tag)
  • length bytes: encoded protobuf data

Note that while there are 24 bits available for the length, the actual maximum length depends on the tag. For TagV1, only 15 bits are used (MaxMessageSizeV1).

Index

Constants

View Source
const (
	// DataLength is the number of bits used for the length of encoded protobuf data.
	DataLength = 24

	// MaxMessageSizeV1 is the maximum size of the encoded protobuf messages sent
	// over the wire for the TagV1 tag. While the wire format allows 24 bits for
	// length, TagV1 only uses 15 bits.
	MaxMessageSizeV1 uint32 = 1 << 15
)

Variables

View Source
var (
	// ErrMessageTooLarge is returned when the message exceeds the maximum size
	// allowed for the tag.
	ErrMessageTooLarge = xerrors.New("message too large")
	// ErrUnsupportedTag is returned when an unrecognized tag is encountered.
	ErrUnsupportedTag = xerrors.New("unsupported tag")
)

Functions

func WriteFrame

func WriteFrame(w io.Writer, tag Tag, data []byte) error

WriteFrame writes a framed message with the given tag and data. The data must not exceed 2^DataLength in length.

Types

type Tag

type Tag uint8
const (
	// TagV1 identifies the first revision of the protocol. This version has a maximum
	// data length of MaxMessageSizeV1.
	TagV1 Tag = 1
)

func ReadFrame

func ReadFrame(r io.Reader, buf []byte) (Tag, []byte, error)

ReadFrame reads a framed message, returning the decoded tag and data. If the message size exceeds MaxMessageSizeV1, ErrMessageTooLarge is returned. The provided buf is used if it has sufficient capacity; otherwise a new buffer is allocated. To reuse the buffer across calls, pass in the returned data slice:

buf := make([]byte, initialSize)
for {
    _, buf, _ = ReadFrame(r, buf)
}

Jump to

Keyboard shortcuts

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