jsonrpc

package
v0.0.0-...-a2ce4e4 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoResult = errors.New("no result in JSON-RPC response")
)

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(ct codec.CodecType) *Client

func (*Client) BatchCall

func (c *Client) BatchCall(batch []api.BatchElem, reader MessageReader) error

func (*Client) Call

func (c *Client) Call(result interface{}, method string, args interface{}, reader MessageReader) error

type Message

type Message struct {
	Version string `json:"jsonrpc,omitempty"`
	// The type of the ID field must be json.Message because the interface{} type cannot perform type comparisons correctly during the process.
	// For example, in respWait(sync.Map), the request is of type int, but it becomes float64 when in response.
	ID     json.RawMessage `json:"id,omitempty"`
	Method string          `json:"method,omitempty"`
	// If this is an instance of Subscription, the Params is json.Marshal(api.SubscriptionResult)
	Params json.RawMessage   `json:"params,omitempty"`
	Error  *api.JsonRpcError `json:"error,omitempty"`
	Result json.RawMessage   `json:"result,omitempty"`
}

Message A value of this type can a JSON-RPC request, notification, successful response or error response. Which one it is depends on the fields.

func ParseBatchMessage

func ParseBatchMessage(b []byte) ([]*Message, bool, error)

func (*Message) HasValidID

func (msg *Message) HasValidID() bool

func (*Message) IsCall

func (msg *Message) IsCall() bool

func (*Message) IsNotification

func (msg *Message) IsNotification() bool

func (*Message) IsResponse

func (msg *Message) IsResponse() bool

func (*Message) String

func (msg *Message) String() string

type MessageReader

type MessageReader func(reqs ...*Message) ([]*Message, error)

type Option

type Option struct {
	CodeType codec.CodecType
}

type Server

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

Server represents an RPC Server.

func NewServer

func NewServer(opt Option) *Server

NewServer returns a new Server.

func (*Server) Call

func (server *Server) Call(ctx api.Context, data []byte) interface{}

func (*Server) Register

func (server *Server) Register(receiver interface{}) error

func (*Server) RegisterName

func (server *Server) RegisterName(name string, receiver interface{}) error

RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.

Jump to

Keyboard shortcuts

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