Documentation
¶
Overview ¶
Package jsonrpc reads, writes and inspects newline-delimited JSON-RPC 2.0 messages without decoding fields actp does not need, so unknown fields survive.
Index ¶
- Constants
- func CheckEnvelope(raw []byte) error
- type Ambiguous
- type Error
- type Kind
- type Message
- func NewError(id json.RawMessage, code int, message string, data any) *Message
- func NewNotification(method string, params any) (*Message, error)
- func NewRequest(id json.RawMessage, method string, params any) (*Message, error)
- func NewResult(id json.RawMessage, result any) *Message
- func Parse(raw []byte) (*Message, error)
- type Reader
- type Writer
Constants ¶
const ( CodeParseError = -32700 CodeInvalidRequest = -32600 CodeMethodNotFound = -32601 CodeInvalidParams = -32602 CodeInternalError = -32603 CodeServerError = -32000 CodeCancelled = -32800 )
Standard and ACP error codes.
Variables ¶
This section is empty.
Functions ¶
func CheckEnvelope ¶ added in v0.1.1
CheckEnvelope refuses a message that Go's decoding (case-insensitive keys, last one wins) and a peer's exact-key decoding could read differently: a key that differs from an envelope field only in case, or an envelope field given twice. Messages that are not JSON objects are left to Parse.
Types ¶
type Ambiguous ¶ added in v0.1.1
type Ambiguous struct {
Reason string
// ID is the message's id when it has exactly one non-null "id" key, else nil.
ID json.RawMessage
// Request reports whether a method key is present in any spelling.
Request bool
}
Ambiguous is a message whose envelope two JSON decoders can read differently.
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 Message ¶
type Message struct {
Raw json.RawMessage
ID json.RawMessage // nil when absent
Method string
Params json.RawMessage
Result json.RawMessage
Error *Error
}
Message is one JSON-RPC message with its header fields peeked.
func NewNotification ¶
NewNotification builds a notification.
func NewRequest ¶
NewRequest builds a request.
func NewResult ¶
func NewResult(id json.RawMessage, result any) *Message
NewResult builds a success response.
func (*Message) WithParams ¶
WithParams returns a copy of the message with new params.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads one message per line.