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 ¶
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 ¶
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)
}
Click to show internal directories.
Click to hide internal directories.