wire

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	// MaxJSON bounds a single JSON message.
	MaxJSON = 1 << 20
	// MaxFrame bounds the payload of a single binary frame.
	MaxFrame = 16 << 20
)

Variables

View Source
var ErrTooLarge = errors.New("wire: message too large")

ErrTooLarge is returned when a peer announces a message above the limit.

Functions

func ReadFrame

func ReadFrame(r io.Reader, buf []byte) (typ byte, payload []byte, err error)

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 ReadJSON

func ReadJSON(r io.Reader, v any) error

ReadJSON reads one length-prefixed JSON message of at most MaxJSON bytes into v.

func ReadJSONLimit

func ReadJSONLimit(r io.Reader, v any, limit int) error

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

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

WriteFrame writes one binary frame using a single Write call.

func WriteJSON

func WriteJSON(w io.Writer, v any) error

WriteJSON marshals v and writes it as one length-prefixed message using a single Write call.

Types

This section is empty.

Jump to

Keyboard shortcuts

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