Documentation
¶
Overview ¶
Package wire implements the two framings every RemoHop stream protocol is built from:
- JSON messages: a 4-byte big-endian length followed by a JSON document. Used for stream headers, requests, replies and other control messages.
- Binary frames: a 4-byte big-endian length, a 1-byte type and a payload. Used wherever raw bytes dominate (terminal I/O, file data, video).
Neither function is safe for concurrent writers on the same stream; callers that write from several goroutines must serialise with their own mutex.
Index ¶
Constants ¶
const ( // MaxJSON bounds a single JSON message. MaxJSON = 1 << 20 // MaxFrame bounds the payload of a single binary frame. MaxFrame = 16 << 20 )
Variables ¶
var ErrTooLarge = errors.New("wire: message too large")
ErrTooLarge is returned when a peer announces a message above the limit.
Functions ¶
func ReadFrame ¶
ReadFrame reads one binary frame. If buf has enough capacity it is reused for the payload, so the returned slice is only valid until the next call that is handed the same buf.
func ReadJSONLimit ¶
ReadJSONLimit is ReadJSON with a caller-chosen size limit, for places that read from a peer they have less reason to trust.
The body buffer grows only as bytes actually arrive. Allocating the announced length up front would let a peer make us reserve the whole limit for the price of a 4-byte header.
func WriteFrame ¶
WriteFrame writes one binary frame using a single Write call.
Types ¶
This section is empty.