codec

package
v0.0.0-...-83c5f91 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package codec provides a ClientCodec implementation that supports Mindctrl web extension.

Index

Constants

This section is empty.

Variables

View Source
var ErrServerDead = errors.New("server dead")

Error reported by Codec to indicate that the server (not the intermediate MQTT broker) is dead.

Functions

This section is empty.

Types

type Codec

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

Implementation of net/rpc client codec for communicating with the mindctrl browser extension ("server") via websocket connection to an intermediate MQTT broker.

func NewCodec

func NewCodec(url string, name string, server string, options *Options) (*Codec, error)

Create a new net/rpc client codec by connecting to the MQTT broker, subscribing to the relevant topics and watching for alive message from the server.

func (*Codec) Close

func (codec *Codec) Close() error

Close the connection to the intermediate MQTT broker and free any resources used by the codec.

func (*Codec) ReadResponseBody

func (codec *Codec) ReadResponseBody(output interface{}) error

Decode the result from the previous RPC response to the given output object.

Note that if the codec is invalidated by previous dead status message, the function will do nothing and return the error ErrServerDead directly.

func (*Codec) ReadResponseHeader

func (codec *Codec) ReadResponseHeader(response *rpc.Response) error

Receive a RPC response from the server. The function will decode the RPC response and cache the "body" part for the subsequent Codec.ReadResponseBody calls.

The function will also check for status messages. If any "dead" status message is received, the codec will be invalidated and the error ErrServerDead is returned.

func (*Codec) WriteRequest

func (codec *Codec) WriteRequest(request *rpc.Request, input interface{}) error

Submit a RPC request to the server for execution by publishing a message to the server topic.

Note that if the codec is invalidated by previous dead status message, the function will do nothing and return the error ErrServerDead directly.

type Options

type Options struct {
	Username           string // username for the intermediate MQTT broker
	Password           string // password for the intermediate MQTT broker
	WebsocketFrameSize int64  // maximum size of websocket packet
	MqttMessageBuffer  int    // number of MQTT messages buffered by the codec
	MqttKeepAlive      int    // keepalive duration of MQTT connection
}

Options for creating a new codec.

The 'Username' and 'Password' fields contains the credentials used to authenticate with the intermediate MQTT broker. They can be empty if authentication is not needed. By default, they are both empty meaning no authentication is needed.

The 'WebsocketMessageSize' field contains the maximum size of a single websocket message. The minimum size is 32KB, and the default 32MB.

The 'Capacity' field contains the number of MQTT messages to be buffered for processing. The minimum size and the default sizes are both 100.

Jump to

Keyboard shortcuts

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