Documentation ¶
Index ¶
- Variables
- func ParseClient(src []byte) (Type, IMessage, error)
- func ParseServer(src []byte) (Type, IMessage, error)
- func TypeToString(mt Type) string
- type Ack
- type Add
- type Allocate
- type Allocated
- type Bind
- type Claim
- type Claimed
- type Close
- type Closed
- type Echo
- type Error
- type IMessage
- type List
- type MailboxMessage
- type Message
- type NameplateEntry
- type Nameplates
- type Open
- type Ping
- type Pong
- type Release
- type Released
- type Type
- type UnixTime
- type Welcome
- type WelcomeInfo
Constants ¶
This section is empty.
Variables ¶
var ErrUnknown = errors.New("unknown message type")
ErrUnknown the message type provided does not match any known types
Functions ¶
func ParseClient ¶
ParseClient attempts to coerce an incoming json message into it's respective IMessage implementing Message struct. Will return an error if the type cannot be found (ErrUnknown), or an error if the message validation is not met
func ParseServer ¶
ParseServer attempts to coerce an incoming json message into it's respective IMessage implementing Message struct. Will return an error if the type cannot be found (ErrUnknown), or an error if the message validation is not met
func TypeToString ¶
TypeToString converts an incoming message type to it's string enum equivalent
Types ¶
type Add ¶
type Add struct { *Message ID string `json:"id"` Phase string `json:"phase"` Body string `json:"body"` //hex encoded }
Add tells the server to add a message to the mailbox for retrieval later. The body portion is hex encoded.
type Allocate ¶
type Allocate struct {
*Message
}
Allocate is the client asking for a nameplate to be reserved for them to use. The server should respond with an Allocated response
type Bind ¶
Bind allows the client to declare itself to the server and should be the first message the client sends. No other client messages will be accepted until this one is received.
type Claim ¶
Claim allows the client to reserve an arbitrary nameplate of their choosing (given it is available)
type Close ¶
type Close struct { *Message Mood string `json:"mood"` //not sure what these values are actually Mailbox string `json:"mailbox"` //optional }
Close tells the server that the client is closing, or terminating it's binding to the mailbox. It does not release the mailbox.
type Closed ¶
type Closed struct {
*Message
}
Closed confirms to the client that the server has closed their mailbox binding
type Echo ¶
type Echo []byte
Echo wraps a []byte slice to fool the JSON encoder into not string encoding this value. This is used in message loopback, or echo-ing the original client message while maintaining the JSON format.
func (Echo) MarshalJSON ¶
MarshalJSON turns this into JSON. For this instance, it is a strait copy so no data wrangling happens.
type Error ¶
type Error struct { *Message Error string `json:"error"` Orig Echo `json:"orig"` //original message }
Error is a server response to errors in client messages.
type IMessage ¶
IMessage interface is used for tagging message types. Basically just wraps them up with a dummy function so reflection can grab them a bit easier
type List ¶
type List struct {
*Message
}
List is a request from the client to have the server reply with the available nameplates. The server may deny this request. The server fulfills this with the Nameplates
type MailboxMessage ¶
type MailboxMessage struct { *Message Side string `json:"side"` Phase string `json:"phase"` Body string `json:"body"` //hex encoded MsgID string `json:"msg_id"` }
MailboxMessage is the server pushing a mailbox message entry to the client The body field is hex encoded.
type Message ¶
type Message struct { Type Type `json:"type"` ID *string `json:"id,omitempty"` ServerTime UnixTime `json:"server_tx,omitempty"` }
Message base object for communication messages
func NewMessage ¶
NewMessage returns a new Message object with the type filled in
func NewServerMessage ¶
NewServerMessage returns a new Message object with the type and server time filled in
type NameplateEntry ¶
type NameplateEntry struct {
ID string `json:"id"`
}
NameplateEntry is an individual entry in the nameplate response, identified by it's ID
type Nameplates ¶
type Nameplates struct { *Message Nameplates []NameplateEntry `json:"nameplates"` }
Nameplates is the server response to a clients list request (List), and responds with the available nameplates
type Open ¶
Open binds the client to a mailbox. Can only be called once per connection. After this point, old messages are transmited as well as listening for updates to the mailbox in which it will push new ones to the client
type Ping ¶
Ping is a protocol specific ping/pong test from client to server. Ping is sent from client
type Pong ¶
Pong is a protocol specific ping/pong test from client to server. Pong is sent from server in response
type Release ¶
Release tells the server that the client is done with their nameplate/mailbox. The Nameplate field is optional, but should match the same one from Claim, or what is allocated to the client.
type Released ¶
type Released struct {
*Message
}
Released is the servers confirmation that it has released the clients nameplate/mailbox as instructed from the Release
type Type ¶
type Type int
Type enumerates the available message types accepted
const ( TypeUnknown Type = iota TypeAck TypePing TypePong TypeWelcome TypeBind TypeList TypeNameplates TypeAllocate TypeAllocated TypeClaim TypeClaimed TypeRelease TypeReleased TypeOpen TypeMessage TypeAdd TypeClose TypeClosed TypeError //Important! keep this one last )
Available message type enumerations
func DetectType ¶
DetectType takes an incoming JSON string as bytes and attempts to find the messages type field by unmarshalling it into a dummy object. Surprisingly, this was faster then RegExp.
func TypeFromString ¶
TypeFromString converts an incoming string to it's Type equivalent, or TypeUnknown if no matches
func (*Type) FromString ¶
FromString converts the incoming string into the message type it matches, or TypeUnknown if no matches
func (Type) MarshalText ¶
MarshalText converts the enum into a string/text representation
func (*Type) UnmarshalText ¶
UnmarshalText converts the string representation, back into the enum
type UnixTime ¶
UnixTime wraps a time.Time pointer so that we can control the json encoding/decoding of the value. The wormhole protocol has it's time values in unix seconds since epoch.
func NewUnixTime ¶
func NewUnixTime() UnixTime
NewUnixTime returns a new UnixTime object filled to time.Now()
func (UnixTime) MarshalJSON ¶
MarshalJSON reads the json
func (*UnixTime) UnmarshalJSON ¶
UnmarshalJSON writes the json
type Welcome ¶
type Welcome struct { *Message Info WelcomeInfo `json:"welcome"` }
Welcome used for the server to introduce itself to clients when they connect
type WelcomeInfo ¶
type WelcomeInfo struct { //MOTD Message Of The Day. Will be displayed //to connecting clients when received MOTD *string `json:"motd,omitempty"` //Error displays an error message to clients //on connection and they will close immediately. //Used to anounce service termination Error *string `json:"error,omitempty"` //Version advertises a new CLI client version to //the clients Version *string `json:"current_cli_version,omitempty"` }
WelcomeInfo wraps up the welcome information for servers to respond to clients with. This is JSON encoded so the type is provided for convenience.