wire

package
v0.13.23 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package wire is the shared G1 frame envelope (build-plan.md gap resolution G1): one length-prefixed, type-tagged frame carries every message on both the client<->daemon and daemon<->shim sockets.

Wire format: a 4-byte big-endian length L, then 1 type byte, then L-1 payload bytes. L == len(payload)+1, so an empty payload has L == 1 and a maximal payload (MaxFrame-1 bytes) has L == MaxFrame.

Index

Constants

View Source
const MaxFrame = 1 << 20 // 1 MiB

MaxFrame is the largest legal declared frame length L (payload+1 type byte), the anti-DoS cap enforced before any body allocation or read.

internal/skeleton's connection demux (handleConn) routes a fresh connection to the protocol server the instant its first byte is 0x00, relying on every legal frame's 4-byte big-endian length prefix having a zero most-significant byte — see the guard immediately below, which fails to compile if that ever stops holding.

Variables

View Source
var ErrFrameTooLarge = errors.New("wire: frame exceeds MaxFrame")

ErrFrameTooLarge is returned when a payload (WriteFrame) or a declared length (ReadFrame) exceeds MaxFrame.

View Source
var ErrUnknownType = errors.New("wire: unknown frame type")

ErrUnknownType is returned when a frame's type tag is outside the frozen set above.

Functions

func WriteFrame

func WriteFrame(w io.Writer, t Type, payload []byte) error

WriteFrame encodes t and payload as one frame and writes it to w. It rejects payloads larger than MaxFrame-1 without writing anything.

Types

type Type

type Type byte

Type identifies the payload a frame carries.

const (
	TControl  Type = 0x01
	TDataOut  Type = 0x02
	TDataIn   Type = 0x03
	TSnapshot Type = 0x04
)

The frozen set of frame types.

func ReadFrame

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

ReadFrame reads one frame from r and returns its type and payload.

The declared length is checked against MaxFrame before any body allocation or read (the anti-DoS cap). A reader exhausted exactly at a frame boundary yields io.EOF; a truncated header or body yields io.ErrUnexpectedEOF.

Jump to

Keyboard shortcuts

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