Documentation
¶
Overview ¶
Package rpc implements bounded bidirectional JSON-RPC 2.0 over a byte stream.
Index ¶
- Constants
- Variables
- type Error
- type Handler
- type Peer
- func (p *Peer) Call(ctx context.Context, method string, params any, result any) error
- func (p *Peer) CallEmpty(ctx context.Context, method string, params any) error
- func (p *Peer) Close() error
- func (p *Peer) Done() <-chan struct{}
- func (p *Peer) Handle(method string, handler Handler) error
- func (p *Peer) HandleLossyNotification(method string, handler Handler) error
- func (p *Peer) Notify(ctx context.Context, method string, params any) error
- func (p *Peer) Serve(ctx context.Context) error
- func (p *Peer) TerminateProtocol(cause error)
- func (p *Peer) TryNotifyLossy(method string, params any) (bool, error)
Constants ¶
const ( Version = "2.0" MaxMessageBytes = 1 << 20 )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct {
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data,omitempty"`
}
Error is a JSON-RPC error object.
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
Peer owns one bidirectional JSON-RPC connection. Serve must run while calls are made.
func NewPeer ¶
NewPeer takes ownership of an established connection and closes it on shutdown. The connection must honor net.Conn's deadline and Close semantics so blocked I/O can be interrupted. Callers must not read, write, or set deadlines on conn after handing it to the peer.
func (*Peer) CallEmpty ¶
CallEmpty sends a request whose successful response is exactly an empty JSON object. It rejects null, scalars, arrays, and objects with fields.
func (*Peer) Close ¶
Close terminates the connection and unblocks all calls. It is safe to repeat. It joins the transport workers without waiting for active handlers to return.
func (*Peer) HandleLossyNotification ¶
HandleLossyNotification registers a method whose notifications may be dropped, and counted, when the inbound method queue is saturated.
func (*Peer) Serve ¶
Serve reads and dispatches messages until the connection, context, or protocol fails.
func (*Peer) TerminateProtocol ¶
TerminateProtocol marks the peer unusable without waiting for active handlers to join. It is safe to call from a reentrant handler.