makerbot-rpc: github.com/tjhorner/makerbot-rpc/jsonrpc Index | Files

package jsonrpc

import "github.com/tjhorner/makerbot-rpc/jsonrpc"

Package jsonrpc implements MakerBot's non-standard JSON-RPC 2.0 protocol.

Index

Package Files

client.go jsonreader.go jsonrpc.go

type Client Uses

type Client struct {
    IP   string
    Port string
    // contains filtered or unexported fields
}

Client is a JSON-RPC client

func NewClient Uses

func NewClient(ip, port string) *Client

NewClient creates a new JSON-RPC client

func (*Client) Call Uses

func (c *Client) Call(serviceMethod string, args, reply interface{}) error

Call calls the remote JSON-RPC server with `serviceMethod`

func (*Client) Close Uses

func (c *Client) Close() error

Close closes the underlying TCP connection

func (*Client) Connect Uses

func (c *Client) Connect() error

Connect connects to the remote JSON-RPC server

func (*Client) GetRawData Uses

func (c *Client) GetRawData(length int) []byte

GetRawData grabs raw data from the TCP connection until `length` is reached. The captured data is returned as an array of bytes.

func (*Client) HandleReadError Uses

func (c *Client) HandleReadError(cb func(error))

HandleReadError calls `cb` when an error occurs while reading from the underlying TCP socket

func (*Client) Subscribe Uses

func (c *Client) Subscribe(namespace string, cb func(message json.RawMessage)) error

Subscribe subscribes to a notification channel that will be sent by the remote server. Every time something is received via that channel, `cb` will be called with the raw JSON the server sent in the `Params`. From there, you should unmarshal it yourself.

func (*Client) Unsubscribe Uses

func (c *Client) Unsubscribe(namespace string)

Unsubscribe will unsubscribe any listeners from specified notification channel. It is safe to call this method even if there is nothing subscribed to the channel.

func (*Client) Write Uses

func (c *Client) Write(bs []byte) (int, error)

Write writes bytes to the underlying TCP socket.

type JSONReader Uses

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

JSONReader is a Go re-implementation of the JsonReader from MakerBot's C++ jsonrpc library: https://github.com/makerbot/jsonrpc/blob/develop/src/main/cpp/jsonreader.cpp

func NewJSONReader Uses

func NewJSONReader(done func([]byte) error) JSONReader

NewJSONReader creates a new JSONReader instance

func (*JSONReader) GetRawData Uses

func (r *JSONReader) GetRawData(length int) []byte

GetRawData grabs raw data from the TCP connection until `length` is reached. The captured data is returned as an array of bytes.

func (*JSONReader) Reset Uses

func (r *JSONReader) Reset()

Reset resets

func (*JSONReader) Write Uses

func (r *JSONReader) Write(bs []byte) (n int, err error)

Write feeds the JSONReader a slice of bytes

Package jsonrpc imports 6 packages (graph) and is imported by 1 packages. Updated 2019-09-14. Refresh now. Tools for package owners.