JSONRPC

package
v0.0.0-...-357ca8a Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

JSON-RPC is a standard which wraps a method call in a JSON object. The object has a particular structure and identifies which method is called, the parameters to that function, and carries an ID to keep track of responses. This class implements that standard on top of data structure; you will have to convert between a data structure and JSON with other functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsJSONRPC() Instance
}

type ErrorCode

type ErrorCode int //gd:JSONRPC.ErrorCode
const (
	// The request could not be parsed as it was not valid by JSON standard ([JSON.Parse] failed).
	//
	// [JSON.Parse]: https://pkg.go.dev/graphics.gd/classdb/JSON#Instance.Parse
	ParseError ErrorCode = -32700
	// A method call was requested but the request's format is not valid.
	InvalidRequest ErrorCode = -32600
	// A method call was requested but no function of that name existed in the JSONRPC subclass.
	MethodNotFound ErrorCode = -32601
	// A method call was requested but the given method parameters are not valid. Not used by the built-in JSONRPC.
	InvalidParams ErrorCode = -32602
	// An internal error occurred while processing the request. Not used by the built-in JSONRPC.
	InternalError ErrorCode = -32603
)

type Expanded

type Expanded = MoreArgs

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsJSONRPC

func (self *Extension[T]) AsJSONRPC() Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.JSONRPC

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AsJSONRPC

func (self Instance) AsJSONRPC() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) ID

func (self Instance) ID() ID

func (Instance) MakeNotification

func (self Instance) MakeNotification(method string, params any) Notification

Returns a dictionary in the form of a JSON-RPC notification. Notifications are one-shot messages which do not expect a response.

- 'method': Name of the method being called.

- 'params': An array or dictionary of parameters being passed to the method.

func (Instance) MakeRequest

func (self Instance) MakeRequest(method string, params any, id any) Request

Returns a dictionary in the form of a JSON-RPC request. Requests are sent to a server with the expectation of a response. The ID field is used for the server to specify which exact request it is responding to.

- 'method': Name of the method being called.

- 'params': An array or dictionary of parameters being passed to the method.

- 'id': Uniquely identifies this request. The server is expected to send a response with the same ID.

func (Instance) MakeResponse

func (self Instance) MakeResponse(result any, id any) Response

When a server has received and processed a request, it is expected to send a response. If you did not want a response then you need to have sent a Notification instead.

- 'result': The return value of the function which was called.

- 'id': The ID of the request this response is targeted to.

func (Instance) MakeResponseError

func (self Instance) MakeResponseError(code int, message string) ResponseError

Creates a response which indicates a previous reply has failed in some way.

- 'code': The error code corresponding to what kind of error this is. See the ErrorCode constants.

- 'message': A custom message about this error.

- 'id': The request this error is a response to.

func (Instance) MoreArgs

func (self Instance) MoreArgs() MoreArgs

MoreArgs enables certain functions to be called with additional 'optional' arguments.

func (Instance) ProcessAction

func (self Instance) ProcessAction(action any) any

Given a Dictionary which takes the form of a JSON-RPC request: unpack the request and run it. Methods are resolved by looking at the field called "method" and looking for an equivalently named function in the JSONRPC object. If one is found that method is called.

To add new supported methods extend the JSONRPC class and call ProcessAction on your subclass.

'action': The action to be run, as a Dictionary in the form of a JSON-RPC request or notification.

func (Instance) ProcessString

func (self Instance) ProcessString(action string) string

func (Instance) SetMethod

func (self Instance) SetMethod(name string, callback Callable.Function)

Registers a callback for the given method name.

- 'name' The name that clients can use to access the callback.

- 'callback' The callback which will handle the specific method.

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type MoreArgs

type MoreArgs [1]gdclass.JSONRPC

MoreArgs is a container for Instance functions with additional 'optional' arguments.

func (MoreArgs) MakeResponseError

func (self MoreArgs) MakeResponseError(code int, message string, id any) ResponseError

Creates a response which indicates a previous reply has failed in some way.

- 'code': The error code corresponding to what kind of error this is. See the ErrorCode constants.

- 'message': A custom message about this error.

- 'id': The request this error is a response to.

func (MoreArgs) ProcessAction

func (self MoreArgs) ProcessAction(action any, recurse bool) any

Given a Dictionary which takes the form of a JSON-RPC request: unpack the request and run it. Methods are resolved by looking at the field called "method" and looking for an equivalently named function in the JSONRPC object. If one is found that method is called.

To add new supported methods extend the JSONRPC class and call ProcessAction on your subclass.

'action': The action to be run, as a Dictionary in the form of a JSON-RPC request or notification.

type Notification

type Notification struct {
	Method string      `gd:"method"`
	Params interface{} `gd:"params"`
}

type Request

type Request struct {
	Method string      `gd:"method"`
	Params interface{} `gd:"params"`
	ID     string      `gd:"id"`
}

type Response

type Response struct {
	Result interface{} `gd:"result"`
	ID     string      `gd:"id"`
}

type ResponseError

type ResponseError struct {
	Code    int    `gd:"code"`
	Message string `gd:"message"`
	ID      int    `gd:"id"`
}

Jump to

Keyboard shortcuts

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