Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Packets = map[MessagePurpose]interface{}{ Subscribe: &EventRequest{}, Unsubscribe: &EventRequest{}, Event: &EventResponse{}, Error: &ErrorResponse{}, Response: &CommandResponse{}, Command: &CommandRequest{}, }
Packets is a map to translate message purposes to their corresponding packets.
Functions ¶
This section is empty.
Types ¶
type CommandRequest ¶
type CommandRequest struct { // CommandLine is the full raw command line to be executed. The command line must not include the leading // slash. For example 'tell player this was sent using ws'. CommandLine string `json:"commandLine"` // Version is the version of the packet. Currently this is 1. Version int `json:"version"` }
CommandRequest is used to send a raw command line to the client. The client itself will do the processing of its arguments.
type CommandResponse ¶
type CommandResponse json.RawMessage
CommandResponse is a merely a JSON raw message, because its value depends on what command was executed.
type ErrorResponse ¶
type ErrorResponse struct { // StatusMessage is a string explaining the error that occurred. StatusMessage string `json:"statusMessage"` // StatusCode is the type of the error that occurred. StatusCode int `json:"statusCode"` }
ErrorResponse is sent by the client when an error occurs during the process of communicating.
type EventRequest ¶
type EventRequest struct { // EventName is the name of the event, for example 'BlockPlaced'. EventName event.Name `json:"eventName"` }
EventRequest is sent by the server to request the client to start sending events of a particular type to the server.
type EventResponse ¶
type EventResponse struct { // EventName is the name of the event, for example 'BlockPlaced'. EventName event.Name `json:"eventName"` // Measurements ... Measurements event.Measurements `json:"measurements"` // Properties is a collection of properties (un)specific to an event. A part of these properties are // shared among all events, others are specific to this event. Properties json.RawMessage `json:"properties"` }
EventResponse is sent by the client. It holds information about a particular event listened on by the sever.
type Header ¶
type Header struct { // RequestID is a UUID specific to the request. RequestID string `json:"requestId"` // MessagePurpose is the purpose of the request. To subscribe to an event, this is 'subscribe'. To // unsubscribe from an event, this is 'unsubscribe'. For an event response, this is 'event'. MessagePurpose MessagePurpose `json:"messagePurpose"` // Version is the version of the request. Currently 1. Version int `json:"version"` }
Header describes the header of a packet. Each packet shares the same header.
type MessagePurpose ¶
type MessagePurpose string
MessagePurpose is the purpose a JSON message was sent.
const ( Subscribe MessagePurpose = "subscribe" Unsubscribe MessagePurpose = "unsubscribe" Event MessagePurpose = "event" Error MessagePurpose = "error" Command MessagePurpose = "commandRequest" Response MessagePurpose = "commandResponse" )
type Packet ¶
type Packet struct { Header Header `json:"header"` Body interface{} `json:"body"` }
Packet is the main struct that describes every packet sent between client and server to communicate. Each packet shares the same header, but a different body.
func NewCommandRequest ¶
NewCommandRequest returns a packet for a raw command to be executed.
func NewEventRequest ¶
func NewEventRequest(eventName event.Name, purpose MessagePurpose) Packet
NewEventRequest returns an event request for a particular event name and action.