protocol

package
v0.1.0-alpha.5 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 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 protocol implements Sweef's wire format: a length-prefixed, JSON-RPC-2.0 compatible framing that is deliberately close enough to the Chrome DevTools Protocol (CDP) that existing CDP clients can attach with minimal shimming, while staying tiny and streaming-friendly.

Frame layout (little-endian):

[4 bytes] magic 'S','W','E','F'
[4 bytes] payload length (uint32, max 64 MiB)
[N bytes] UTF-8 JSON payload (a JsonRpc Request/Response/Notification)

Index

Constants

View Source
const (
	Magic       = "SWF1"
	MaxFrameLen = 64 << 20 // 64 MiB hard cap keeps hostile peers from OOM-ing us
)

Variables

View Source
var (
	ErrBadMagic = errors.New("protocol: bad magic")
	ErrTooLarge = errors.New("protocol: frame exceeds limit")
	ErrClosed   = errors.New("protocol: connection closed")
)

Functions

func WriteMsg

func WriteMsg(w io.Writer, m *Message) error

WriteMsg serialises m into one frame and writes it.

Types

type Conn

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

Conn wraps a bidirectional stream with mutexed writes so many goroutines (engine events, RPC replies, MCP notifications) can share one socket.

func NewConn

func NewConn(rw io.ReadWriteCloser) *Conn

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) Done

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

func (*Conn) Read

func (c *Conn) Read(buf []byte) (*Message, []byte, error)

func (*Conn) Write

func (c *Conn) Write(m *Message) error

type Message

type Message struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      int64           `json:"id,omitempty"`
	Method  string          `json:"method,omitempty"`
	Params  json.RawMessage `json:"params,omitempty"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *RpcError       `json:"error,omitempty"`
}

Message is one JsonRpc envelope. Either Method != "" (request/notification), or Result/Error != nil (response).

func ReadMsg

func ReadMsg(r io.Reader, buf []byte) (*Message, []byte, error)

ReadMsg reads exactly one frame. Caller-owned buffer is reused safely.

type RpcError

type RpcError struct {
	Code    int             `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data,omitempty"`
}

func (*RpcError) Error

func (e *RpcError) Error() string

Jump to

Keyboard shortcuts

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