wire

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 13 Imported by: ? 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 is the link between icebath and the code of an extension: frames of the protocol, each the size of its message as a varint and the message in binary on a program's standard input and output, both sides asking and answering the other at once

Index

Constants

View Source
const MaxFrame = 128 << 20

Largest frame either side sends or reads, room for a body of 64 MB and what goes with it

View Source
const Version int32 = 2

Version of the protocol this package speaks, which icebath and the extension tell each other on load

Variables

View Source
var ErrTooLarge = fmt.Errorf("a frame may be at most %d MB", MaxFrame>>20)

Failure of a frame larger than MaxFrame, which is never sent

Functions

func Answer

func Answer(reply *protocolv1.Reply, result proto.Message) error

Reads the result of a reply into result unless it is nil, an answer of nothing leaving it as it is, and a failure as an *Error

func Cause

func Cause(ctx context.Context) context.Context

Context of the call of this side the request served under ctx was asked as part of, as its cause names it. nil for a request asked on its own, or once that call ended

func CauseOf

func CauseOf(ctx context.Context) int64

Id of the request of the other side ctx serves on a link with no Conn, which a request asked under it names as its cause; 0 for none

func Denied

func Denied(format string, args ...any) error

Refusal of what the grants of the manifest do not allow

func Limited

func Limited(format string, args ...any) error

Refusal of a request asked more often than the side answers it

func Read

func Read(r *bufio.Reader, frame *protocolv1.Frame) error

Reads one frame, io.EOF when the stream ended before it began

func Reply

func Reply(id int64, result proto.Message, err error) *protocolv1.Frame

Reply of the request with the id: its error, or its result, nothing answering with google.protobuf.Empty

func Serving

func Serving(ctx context.Context, id int64) context.Context

Context serving the request of the other side with the id on a link with no Conn, such as that of a module, so a request asked under it names it as its cause

func Unavailable

func Unavailable(format string, args ...any) error

Refusal of a request nothing can answer now, such as a question in a session nobody watches

func Unknown

func Unknown(format string, args ...any) error

Failure of a request for a registration or a kind of request the side does not have

func Write

func Write(w io.Writer, frame *protocolv1.Frame) error

Writes one frame, its size first, in a single write

Types

type Conn

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

Connection over one stream of frames: requests sent and answered both ways at once, each request served on its own goroutine and the notices one after another in the order they came

func NewConn

func NewConn(in io.Reader, out io.Writer, handle Handler) *Conn

Connection reading frames from in and writing them to out, serving the other side's requests with handle

func (*Conn) Call

func (c *Conn) Call(ctx context.Context, request *protocolv1.Frame, result proto.Message) error

Sends a request, its id assigned here, and waits for its reply, whose result is read into result unless it is nil. A request asked as ctx serves one of the other side names that one as its cause, and one whose context serves none names the one request of the other side served now while there is one alone. A reply of a failure returns an *Error, and a context that ends first tells the other side to stop

func (*Conn) Done

func (c *Conn) Done() <-chan struct{}

Closed once the stream ended

func (*Conn) Notify

func (c *Conn) Notify(notice *protocolv1.Frame) error

Sends a notice, which is never answered

func (*Conn) Run

func (c *Conn) Run(ctx context.Context) error

Reads frames until the stream ends, then stops what is being served and fails every call still waiting. It returns once the notices that came were served

type Error

type Error struct {
	Message string
	Code    protocolv1.Code
}

Failure of a request, as the side that served it said it

func (*Error) Error

func (e *Error) Error() string

type Handler

type Handler func(ctx context.Context, request *protocolv1.Frame) (proto.Message, error)

Serves one request or notice of the other side, its body saying which. A nil message with no error answers with nothing

Jump to

Keyboard shortcuts

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