wire

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 8 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 carries NDJSON lines over TCP, TLS and WebSocket behind one interface, and tells protocols apart by the first byte a peer sends.

Index

Constants

View Source
const MaxLine = 1 << 20

MaxLine bounds a single incoming line. Envelope parts stay under 512 KiB.

Variables

View Source
var ErrLineTooLong = errors.New("line exceeds 1 MiB")

Functions

func NewPipe

func NewPipe(remote, transport string) (*Pipe, *Pipe)

func ReadLine

func ReadLine(r *bufio.Reader) ([]byte, error)

ReadLine reads one newline-terminated line, without the newline.

Types

type BufConn

type BufConn struct {
	net.Conn
	R *bufio.Reader
}

BufConn is a net.Conn whose first bytes may already sit in a bufio.Reader.

func Sniff

func Sniff(c net.Conn, timeout time.Duration) (byte, *BufConn, error)

Sniff waits for the first byte from c without consuming it.

func (*BufConn) Read

func (c *BufConn) Read(p []byte) (int, error)

type ChanListener

type ChanListener struct {
	// contains filtered or unexported fields
}

ChanListener hands already-accepted connections to an http.Server.

func NewChanListener

func NewChanListener(addr net.Addr) *ChanListener

func (*ChanListener) Accept

func (l *ChanListener) Accept() (net.Conn, error)

func (*ChanListener) Addr

func (l *ChanListener) Addr() net.Addr

func (*ChanListener) Close

func (l *ChanListener) Close() error

func (*ChanListener) Push

func (l *ChanListener) Push(c net.Conn)

type LineConn

type LineConn interface {
	ReadLine() ([]byte, error)
	WriteLine([]byte) error
	Close() error
	RemoteAddr() string
	Transport() string
}

func NewStream

func NewStream(c net.Conn, transport string) LineConn

NewStream wraps a byte stream. If c is a *BufConn its buffered bytes are kept.

func NewWS

func NewWS(c *websocket.Conn, remote, transport string) LineConn

NewWS wraps a WebSocket where each text message is one line.

type Pipe

type Pipe struct {
	// contains filtered or unexported fields
}

Pipe is an in-memory LineConn pair, used for relay-multiplexed agents and tests.

func (*Pipe) Close

func (p *Pipe) Close() error

func (*Pipe) ReadLine

func (p *Pipe) ReadLine() ([]byte, error)

func (*Pipe) RemoteAddr

func (p *Pipe) RemoteAddr() string

func (*Pipe) Transport

func (p *Pipe) Transport() string

func (*Pipe) WriteLine

func (p *Pipe) WriteLine(b []byte) error

Jump to

Keyboard shortcuts

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