Versions in this module Expand all Collapse all v0 v0.1.5 Oct 26, 2026 Changes in this version + var ErrMessageTooLarge = NewError(-32001, "Message too large") v0.1.4 Oct 20, 2026 v0.1.3 May 23, 2025 Changes in this version + var ErrResponseIsError = errors.New("response is an error") + var ErrResponseNotError = errors.New("response is a response") type Response + func (r *Response) Unmarshal(v any) error + func (r *Response) UnmarshalError(v any) error v0.1.2 May 7, 2025 Changes in this version type TypeHint + func HintType(m json.RawMessage) TypeHint v0.1.1 Apr 28, 2025 v0.1.0 Apr 27, 2025 Changes in this version + const DefaultHTTPReadTimeout + const DefaultHTTPShutdownTimeout + const DefaultPacketBufferSize + const DefaultPoolDialTimeout + const DefaultPoolIdleTimeout + const ProtocolVersion + var DefaultOnHandlerPanic = func(ctx context.Context, req *Request, rec any) + var ErrDecoding = errors.New("jsonrpc2: decoding error") + var ErrEmptyData = errors.New("data is empty") + var ErrEncoding = errors.New("jsonrpc2: encoding error") + var ErrHTTPEmptyResponse = errors.New("jsonrpc2/httpbridge: empty JSON response body") + var ErrHTTPNotJSON = errors.New("jsonrpc2/httpbridge: response Content-Type was not application/json") + var ErrHTTPResponse = errors.New("jsonrpc2/httpbridge: HTTP response error") + var ErrIDNotANumber = errors.New("ID is not a number") + var ErrInternalError = NewError(-32603, "Internal error") + var ErrInvalidParameters = errors.New("Invalid parameters") + var ErrInvalidParams = NewError(-32602, "Invalid params") + var ErrInvalidParamsType = errors.New("jsonrpc2: params must marshal to a JSON object or array") + var ErrInvalidRequest = NewError(-32600, "Invalid Request") + var ErrJSONTooLarge = errors.New("jsonrpc2: JSON payload larger than configured read limit") + var ErrMethodAlreadyExists = errors.New("method already exists in mux") + var ErrMethodNotFound = NewError(-32601, "Method not found") + var ErrNotRawMessage = errors.New("Value is it not a raw message") + var ErrParseError = NewError(-32700, "Parse error") + var ErrRetriesExceeded = errors.New("retries exceeded") + var ErrServerOverloaded = NewError(-32000, "Server overloaded") + var ErrUnknownScheme = errors.New("jsonrpc2: unknown scheme in uri") + var ErrWrongProtocolVersion = errors.New("wrong protocol version for jsonrpc2") + var Marshal = json.Marshal + var NewJSONDecoder = func(r io.Reader) JSONDecoder + var NewJSONEncoder = func(w io.Writer) JSONEncoder + var Unmarshal = json.Unmarshal + func BatchCorrelate(requests Batch[*Request], responses Batch[*Response], ...) + type Batch []B + func NewBatch[B Batchable](size int) Batch[B] + func (b *Batch[B]) Add(v ...B) + func (b *Batch[B]) Contains(id ID) bool + func (b *Batch[B]) Delete(id ID) (B, bool) + func (b *Batch[B]) Get(id ID) (B, bool) + func (b *Batch[B]) Grow(n int) + func (b *Batch[B]) Index(id ID) int + func (b *Batch[B]) Reset() + type BatchBuildable interface + type BatchBuilder struct + func (b *BatchBuilder[B]) Add(method string, params any) error + func (b *BatchBuilder[B]) Call(ctx context.Context) (Batch[*Response], error) + type Batchable interface + type Binder interface + Bind func(ctx context.Context, rpc *RPCServer, stop context.CancelCauseFunc) + func NewFuncBinder(f func(context.Context, *RPCServer, context.CancelCauseFunc)) Binder + type Callbacks struct + OnDecodingError func(ctx context.Context, raw json.RawMessage, err error) + OnEncodingError func(ctx context.Context, value any, err error) + OnExit func(ctx context.Context, err error) + OnHandlerPanic func(ctx context.Context, req *Request, rec any) + type Client struct + func Dial(ctx context.Context, destURI string) (*Client, error) + func DialWithConfig(ctx context.Context, config ClientPoolConfig) (*Client, error) + func (c *Client) Call(ctx context.Context, method string, params any) (*Response, error) + func (c *Client) Close() + func (c *Client) NewNotificationBatch(size int) *BatchBuilder[*Notification] + func (c *Client) NewRequestBatch(size int) *BatchBuilder[*Request] + func (c *Client) Notify(ctx context.Context, method string, params any) error + func (c *Client) SetDefaultTimeout(d time.Duration) + type ClientPool struct + func NewClientPool(nctx context.Context, config ClientPoolConfig) (*ClientPool, error) + func NewClientPoolWithDialer(nctx context.Context, config ClientPoolConfig, ...) (*ClientPool, error) + func (cp *ClientPool) Call(ctx context.Context, req *Request) (resp *Response, err error) + func (cp *ClientPool) CallBatch(ctx context.Context, req Batch[*Request]) (resp Batch[*Response], err error) + func (cp *ClientPool) CallBatchWithTimeout(ctx context.Context, timeout time.Duration, r Batch[*Request]) (Batch[*Response], error) + func (cp *ClientPool) CallRaw(ctx context.Context, req RawRequest) (resp *Response, err error) + func (cp *ClientPool) CallRawWithTimeout(ctx context.Context, timeout time.Duration, r RawRequest) (*Response, error) + func (cp *ClientPool) CallWithTimeout(ctx context.Context, timeout time.Duration, r *Request) (*Response, error) + func (cp *ClientPool) Close() + func (cp *ClientPool) Notify(ctx context.Context, notify *Notification) (err error) + func (cp *ClientPool) NotifyBatch(ctx context.Context, notify Batch[*Notification]) (err error) + func (cp *ClientPool) NotifyBatchWithTimeout(ctx context.Context, timeout time.Duration, n Batch[*Notification]) error + func (cp *ClientPool) NotifyRaw(ctx context.Context, notify RawNotification) (err error) + func (cp *ClientPool) NotifyRawWithTimeout(ctx context.Context, timeout time.Duration, n RawNotification) error + func (cp *ClientPool) NotifyWithTimeout(ctx context.Context, timeout time.Duration, n *Notification) error + func (cp *ClientPool) Reset() + type ClientPoolConfig struct + AcquireOnCreate bool + DialTimeout time.Duration + IdleTimeout time.Duration + MaxSize int32 + Retries int + URI string + type ContextKey int + const CtxFromAddr + const CtxHTTPRequest + const CtxNetConn + const CtxNetPacketConn + const CtxRPCServer + type Data struct + func (d *Data) IsZero() bool + func (d *Data) MarshalJSON() ([]byte, error) + func (d *Data) RawMessage() json.RawMessage + func (d *Data) TypeHint() TypeHint + func (d *Data) Unmarshal(v any) error + func (d *Data) UnmarshalJSON(data []byte) error + func (d *Data) Value() any + type DeadlineReader interface + SetReadDeadline func(time.Time) error + type DeadlineWriter interface + SetWriteDeadline func(time.Time) error + type Decoder interface + Decode func(ctx context.Context, v any) error + Unmarshal func(data []byte, v any) error + func NewDecoder(r io.Reader) Decoder + type Encoder interface + Encode func(ctx context.Context, v any) error + func NewEncoder(w io.Writer) Encoder + type Error struct + Code int64 + Data ErrorData + Message string + func NewError(code int64, msg string) Error + func NewErrorWithData(code int64, msg string, data any) Error + func (e *Error) IsZero() bool + func (e *Error) UnmarshalJSON(b []byte) error + func (e Error) Error() string + func (e Error) Is(t error) bool + func (e Error) WithData(data any) Error + type ErrorData = Data + func NewErrorData(v any) ErrorData + type HTTPBridge struct + func NewHTTPBridge(url string) *HTTPBridge + func (h *HTTPBridge) Close() error + func (h *HTTPBridge) Decode(ctx context.Context, v any) error + func (h *HTTPBridge) Encode(ctx context.Context, v any) error + func (h *HTTPBridge) Unmarshal(data []byte, v any) error + type HTTPHandler struct + Binder Binder + MaxBytes int64 + NewDecoder NewDecoderFunc + NewEncoder NewEncoderFunc + func NewHTTPHandler(handler Handler) *HTTPHandler + func (h *HTTPHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) + type Handler interface + Handle func(ctx context.Context, req *Request) (result any, err error) + func NewFuncHandler(f func(context.Context, *Request) (any, error)) Handler + type ID struct + func NewID[V int64 | string | json.Number](v V) ID + func NewNullID() ID + func (id *ID) Equal(t ID) bool + func (id *ID) Int64() (int64, error) + func (id *ID) IsNull() bool + func (id *ID) IsZero() bool + func (id *ID) MarshalJSON() ([]byte, error) + func (id *ID) Number() (json.Number, bool) + func (id *ID) String() (string, bool) + func (id *ID) UnmarshalJSON(data []byte) error + func (id *ID) Value() any + type JSONDecoder interface + Decode func(v any) error + type JSONEncoder interface + Encode func(v any) error + type MethodMux struct + func NewMethodMux() *MethodMux + func (mm *MethodMux) Delete(method string) + func (mm *MethodMux) Handle(ctx context.Context, req *Request) (any, error) + func (mm *MethodMux) Methods() []string + func (mm *MethodMux) Register(method string, handler Handler) error + func (mm *MethodMux) RegisterFunc(method string, f func(context.Context, *Request) (any, error)) error + func (mm *MethodMux) Replace(method string, handler Handler) + func (mm *MethodMux) ReplaceFunc(method string, f func(context.Context, *Request) (any, error)) + func (mm *MethodMux) SetDefault(handler Handler) + func (mm *MethodMux) SetDefaultFunc(f func(context.Context, *Request) (any, error)) + type NewDecoderFunc func(r io.Reader) Decoder + type NewEncoderFunc func(w io.Writer) Encoder + type NewPacketDecoderFunc func(conn net.PacketConn) PacketDecoder + type NewPacketEncoderFunc func(conn net.PacketConn) PacketEncoder + type Notification Request + func NewNotification(method string) *Notification + func NewNotificationWithParams(method string, p Params) *Notification + func (n *Notification) AsRequest() *Request + type PacketConnDecoder struct + func NewPacketConnDecoder(conn net.PacketConn) *PacketConnDecoder + func (i *PacketConnDecoder) Close() error + func (i *PacketConnDecoder) DecodeFrom(ctx context.Context, v any) (net.Addr, error) + func (i *PacketConnDecoder) SetIdleTimeout(d time.Duration) + func (i *PacketConnDecoder) SetLimit(n int64) + func (i *PacketConnDecoder) Unmarshal(data []byte, v any) error + type PacketConnEncoder struct + func NewPacketConnEncoder(w net.PacketConn) *PacketConnEncoder + func (i *PacketConnEncoder) Close() error + func (i *PacketConnEncoder) EncodeTo(ctx context.Context, v any, addr net.Addr) error + func (i *PacketConnEncoder) SetIdleTimeout(d time.Duration) + type PacketDecoder interface + DecodeFrom func(ctx context.Context, v any) (net.Addr, error) + Unmarshal func(data []byte, v any) error + func NewPacketDecoder(conn net.PacketConn) PacketDecoder + type PacketEncoder interface + EncodeTo func(ctx context.Context, v any, addr net.Addr) error + func NewPacketEncoder(w net.PacketConn) PacketEncoder + type Params struct + func NewParamsArray[V any, P ~[]V](v P) Params + func NewParamsObject[K comparable, V any, P ~map[K]V](v P) Params + func NewParamsRaw(v json.RawMessage) Params + func (p *Params) IsZero() bool + func (p *Params) MarshalJSON() ([]byte, error) + func (p *Params) RawMessage() json.RawMessage + func (p *Params) TypeHint() TypeHint + func (p *Params) Unmarshal(v any) error + func (p *Params) UnmarshalJSON(data []byte) error + func (p *Params) Value() any + type RPCServer struct + Callbacks Callbacks + Handler Handler + NoRoutines bool + SerialBatch bool + WaitOnClose bool + func NewPacketServer(d PacketDecoder, e PacketEncoder, handler Handler) *RPCServer + func NewRPCServerFromPacket(rw net.PacketConn, handler Handler) *RPCServer + func NewStreamServer(d Decoder, e Encoder, handler Handler) *RPCServer + func NewStreamServerFromIO(rw io.ReadWriter, handler Handler) *RPCServer + func (rp *RPCServer) Close() error + func (rp *RPCServer) Run(ctx context.Context) (err error) + type RawNotification json.RawMessage + type RawRequest json.RawMessage + type RawResponse json.RawMessage + type Request struct + ID ID + Jsonrpc Version + Method string + Params Params + func NewRequestWithParams[I int64 | string](id I, method string, p Params) *Request + func NewRequest[I int64 | string](id I, method string) *Request + func (r *Request) AsNotification() *Notification + func (r *Request) IsNotification() bool + func (r *Request) ResponseWithError(e error) *Response + func (r *Request) ResponseWithResult(result any) *Response + type Response struct + Error Error + ID ID + Jsonrpc Version + Result Result + func NewResponseError(e error) *Response + func NewResponseWithError[I int64 | string](id I, e error) *Response + func NewResponseWithResult[I int64 | string](id I, r any) *Response + func (r *Response) IsError() bool + type Result = Data + func NewResult(v any) Result + type Server struct + Binder Binder + HTTPReadTimeout time.Duration + HTTPShutdownTimeout time.Duration + NewDecoder NewDecoderFunc + NewEncoder NewEncoderFunc + NewPacketDecoder NewPacketDecoderFunc + NewPacketEncoder NewPacketEncoderFunc + PacketRoutines int + func NewServer(handler Handler) *Server + func (s *Server) ListenAndServe(ctx context.Context, listenURI string) error + func (s *Server) Serve(ctx context.Context, ln net.Listener) error + func (s *Server) ServePacket(ctx context.Context, packetConn net.PacketConn) error + type StreamDecoder struct + func NewStreamDecoder(r io.Reader) *StreamDecoder + func (i *StreamDecoder) Close() error + func (i *StreamDecoder) Decode(ctx context.Context, v any) error + func (i *StreamDecoder) SetIdleTimeout(d time.Duration) + func (i *StreamDecoder) SetLimit(n int64) + func (i *StreamDecoder) Unmarshal(data []byte, v any) error + type StreamEncoder struct + func NewStreamEncoder(w io.Writer) *StreamEncoder + func (i *StreamEncoder) Close() error + func (i *StreamEncoder) Encode(ctx context.Context, v any) error + func (i *StreamEncoder) SetIdleTimeout(d time.Duration) + type TransportClient struct + func DialTransport(ctx context.Context, destURI string) (*TransportClient, error) + func NewTransportClient(e Encoder, d Decoder) *TransportClient + func NewTransportClientIO(rw io.ReadWriter) *TransportClient + func (c *TransportClient) Call(ctx context.Context, r *Request) (*Response, error) + func (c *TransportClient) CallBatch(ctx context.Context, r Batch[*Request]) (Batch[*Response], error) + func (c *TransportClient) CallBatchWithTimeout(ctx context.Context, timeout time.Duration, r Batch[*Request]) (Batch[*Response], error) + func (c *TransportClient) CallRaw(ctx context.Context, r RawRequest) (*Response, error) + func (c *TransportClient) CallRawWithTimeout(ctx context.Context, timeout time.Duration, r RawRequest) (*Response, error) + func (c *TransportClient) CallWithTimeout(ctx context.Context, timeout time.Duration, r *Request) (*Response, error) + func (c *TransportClient) Close() error + func (c *TransportClient) Notify(ctx context.Context, n *Notification) error + func (c *TransportClient) NotifyBatch(ctx context.Context, n Batch[*Notification]) error + func (c *TransportClient) NotifyBatchWithTimeout(ctx context.Context, timeout time.Duration, n Batch[*Notification]) error + func (c *TransportClient) NotifyRaw(ctx context.Context, n RawNotification) error + func (c *TransportClient) NotifyRawWithTimeout(ctx context.Context, timeout time.Duration, n RawNotification) error + func (c *TransportClient) NotifyWithTimeout(ctx context.Context, timeout time.Duration, n *Notification) error + type TypeHint int + const TypeArray + const TypeBool + const TypeEmpty + const TypeNotJSON + const TypeNull + const TypeNumber + const TypeObject + const TypeString + const TypeUnknown + type Version struct + func (v *Version) IsValid() bool + func (v *Version) UnmarshalJSON(data []byte) error + func (v Version) MarshalJSON() ([]byte, error)