jsonrpc2

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2021 License: BSD-3-Clause Imports: 6 Imported by: 1

Documentation

Index

Constants

View Source
const (

	// CodeParseError means an invalid JSON was received by the server.
	// An error occurred on the server while parsing the JSON text.
	CodeParseError = -32700
	//CodeInvalidRequest means the JSON sent is not a valid Request object.
	CodeInvalidRequest = -32600
	// CodeMethodNotFound is generated when the method does not exist / is not available.
	CodeMethodNotFound = -32601
	// CodeInvalidParams means invalid method parameter(s) were found.
	CodeInvalidParams = -32602
	// CodeInternalError is used to denote internal JSON-RPC error
	CodeInternalError = -32603
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultTransport added in v0.0.5

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

DefaultTransport is a default implementation of the `Transport` interface

func MakeTransport added in v0.0.5

func MakeTransport(io Stream) *DefaultTransport

MakeTransport creates a default transport mechanism over a `Stream`

func (*DefaultTransport) Read added in v0.0.5

func (dt *DefaultTransport) Read() ([]byte, int64, error)

func (*DefaultTransport) SendErrorResponse added in v0.0.5

func (dt *DefaultTransport) SendErrorResponse(id *ID, err *Error)

func (*DefaultTransport) SendNotification added in v0.0.5

func (dt *DefaultTransport) SendNotification(method string, data []byte)

func (*DefaultTransport) SendResponse added in v0.0.5

func (dt *DefaultTransport) SendResponse(id *ID, data []byte)

SendResponse sends

func (*DefaultTransport) Write added in v0.0.5

func (dt *DefaultTransport) Write(data []byte) (int64, error)

type Error

type Error struct {
	Code    int64            `json:"code"`
	Message string           `json:"message"`
	Data    *json.RawMessage `json:"data"`
}

Error is a JSON RPC 2.0 Error see https://www.jsonrpc.org/specification for details

type ID

type ID struct {
	NumberID int64
	StringID string
}

ID is a Request identifier, which is either a number or string

func (*ID) MarshalJSON

func (id *ID) MarshalJSON() ([]byte, error)

MarshalJSON converts ID to JSON using the String representation first if it has a non-zero value, otherwise uses the Number value

func (*ID) String

func (id *ID) String() string

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(js []byte) error

UnmarshalJSON decodes JSON RPC 2.0 ID

type Request

type Request struct {
	Version VersionTag       `json:"jsonrpc"`
	ID      *ID              `json:"id,omitempty"`
	Method  string           `json:"method"`
	Params  *json.RawMessage `json:"params,omitempty"`
}

Request is a JSON RPC 2.0 Request. If an ID is not present then it is a notification see https://www.jsonrpc.org/specification for details

type Response

type Response struct {
	Version VersionTag       `json:"jsonrpc"`
	ID      *ID              `json:"id,omitempty"`
	Result  *json.RawMessage `json:"result,omitempty"`
	Error   *Error           `json:"error,omitempty"`
}

Response is a JSON RPC 2.0 Response see https://www.jsonrpc.org/specification for details

type Stream added in v0.0.5

type Stream interface {
	//Read gets the next message from the stream
	Read() (data []byte, length int64, err error)
	Write(data []byte) (n int64, err error)
}

Stream is a transport abstraction free IO Stream for JSON-RPC 2.0

func NewStream added in v0.0.5

func NewStream(in io.Reader, out io.Writer) Stream

NewStream communicates LSP over an io Reader and Writer

type Transport added in v0.0.5

type Transport interface {
	SendResponse(id *ID, data []byte)
	SendNotification(data []byte)
	SendErrorResponse(id *ID, err *Error)
}

Transport is a protocol-agnostic transport interface for JSON RPC 2.0 messages

type VersionTag

type VersionTag struct {
}

VersionTag encodes the JSON RPC 2.0 protocol version

func (VersionTag) MarshalJSON

func (VersionTag) MarshalJSON() ([]byte, error)

MarshalJSON encodes the JSON RPC 2.0 protocol number

func (VersionTag) UnmarshalJSON

func (VersionTag) UnmarshalJSON(js []byte) error

UnmarshalJSON decodes version, and errors if anything other than 2.0 is found

Jump to

Keyboard shortcuts

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