v1

package
v0.0.0-...-e0fb3b4 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package v1 contains the GueaaS v1 protocol implementation.

Protocol Specification

The v1 protocol is message and session based. Messages are exchanged between the client and the server within a session using an interconnect. A session is a persistent "session" (connection) made up of the exchanged messages between two participants. One participant has the role of server, the other the role of client. The client dials up the server. Message are the only atomic construct within a session. Messages are independent and never block the interconnect.

Messages may be exchanged over any interconnect, however, this package only implements support for the nanomsg (Scalability Protocols) Socket interface as provided by mangos. The PAIR protocol is recommended for communication.

Messages are encoded using the MessagePack format. The Golang struct type definitions serve as the authoritative specification as encoded by the msgp code generator. Each message send over the interconnect as bytes consists solely of the encoded struct.

The v1 protocol only has two message types. This allows straight-forward decoding without prior message type deduction. The client always sends ClientMessage messages and the server always sends ServerMessage messages.

The lifetime of the session between server and client is entirely managed by the interconnect mechanism. E.g. closing the nanomsg Socket is interpreted as the session end by the implementation in this package.

Index

Constants

View Source
const (
	MessageTypeClient protocol.MessageType = iota + 1
	MessageTypeServer
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientMessage

type ClientMessage struct {
	ID    uint64 `msg:"id"`
	Input string `msg:"input"`
}

func (*ClientMessage) BuildMessage

func (c *ClientMessage) BuildMessage() (*mangos.Message, error)

func (*ClientMessage) DecodeMsg

func (z *ClientMessage) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (ClientMessage) EncodeMsg

func (z ClientMessage) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (ClientMessage) MarshalMsg

func (z ClientMessage) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*ClientMessage) MarshalTo

func (c *ClientMessage) MarshalTo(msg *mangos.Message) error

func (ClientMessage) Msgsize

func (z ClientMessage) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*ClientMessage) SendTo

func (c *ClientMessage) SendTo(socket mangos.Socket) error

func (*ClientMessage) UnmarshalFrom

func (c *ClientMessage) UnmarshalFrom(msg *mangos.Message) error

func (*ClientMessage) UnmarshalMsg

func (z *ClientMessage) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type ServerError

type ServerError uint64
const (
	ErrorNone ServerError = iota
	ErrorServiceUnavailable
	ErrorRequestError
)

func (*ServerError) DecodeMsg

func (z *ServerError) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (ServerError) EncodeMsg

func (z ServerError) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (ServerError) MarshalMsg

func (z ServerError) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (ServerError) Msgsize

func (z ServerError) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (ServerError) String

func (s ServerError) String() string

func (*ServerError) UnmarshalMsg

func (z *ServerError) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type ServerMessage

type ServerMessage struct {
	ID     uint64               `msg:"id"`
	Error  ServerError          `msg:"error"`
	Result common.GuessitResult `msg:"result"`
}

func (*ServerMessage) BuildMessage

func (s *ServerMessage) BuildMessage() (*mangos.Message, error)

func (*ServerMessage) DecodeMsg

func (z *ServerMessage) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*ServerMessage) EncodeMsg

func (z *ServerMessage) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*ServerMessage) MarshalMsg

func (z *ServerMessage) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*ServerMessage) MarshalTo

func (s *ServerMessage) MarshalTo(msg *mangos.Message) error

func (*ServerMessage) Msgsize

func (z *ServerMessage) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*ServerMessage) SendTo

func (s *ServerMessage) SendTo(socket mangos.Socket) error

func (*ServerMessage) UnmarshalFrom

func (s *ServerMessage) UnmarshalFrom(msg *mangos.Message) error

func (*ServerMessage) UnmarshalMsg

func (z *ServerMessage) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

Jump to

Keyboard shortcuts

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