message

package
v1.0.0-rc1.0...-c90ccdb Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinLenSignal represents the minimum length
	// of binary/UTF8 encoded signal messages.
	// binary/UTF8 signal message structure:
	//  1. message type (1 byte)
	//  2. name length flag (1 byte)
	//  3. name (n bytes, optional if name length flag is 0)
	//  4. payload (n bytes, at least 1 byte)
	MinLenSignal = int(3)

	// MinLenSignalUtf16 represents the minimum length
	// of UTF16 encoded signal messages.
	// UTF16 signal message structure:
	//  1. message type (1 byte)
	//  2. name length flag (1 byte)
	//  3. name (n bytes, optional if name length flag is 0)
	//  4. header padding (1 byte, required if name length flag is odd)
	//  5. payload (n bytes, at least 2 bytes)
	MinLenSignalUtf16 = int(4)

	// MinLenRequest represents the minimum length
	// of binary/UTF8 encoded request messages.
	// binary/UTF8 request message structure:
	//  1. message type (1 byte)
	//  2. message id (8 bytes)
	//  3. name length flag (1 byte)
	//  4. name (from 0 to 255 bytes, optional if name length flag is 0)
	//  5. payload (n bytes, at least 1 byte or optional if name len > 0)
	MinLenRequest = int(11)

	// MinLenRequestUtf16 represents the minimum length
	// of UTF16 encoded request messages.
	// UTF16 request message structure:
	//  1. message type (1 byte)
	//  2. message id (8 bytes)
	//  3. name length flag (1 byte)
	//  4. name (n bytes, optional if name length flag is 0)
	//  5. header padding (1 byte, required if name length flag is odd)
	//  6. payload (n bytes, at least 2 bytes)
	MinLenRequestUtf16 = int(11)

	// MinLenReply represents the minimum length
	// of binary/UTF8 encoded reply messages.
	// binary/UTF8 reply message structure:
	//  1. message type (1 byte)
	//  2. message id (8 bytes)
	//  3. payload (n bytes, optional or at least 1 byte)
	MinLenReply = int(9)

	// MinLenReplyUtf16 represents the minimum length
	// of UTF16 encoded reply messages.
	// UTF16 reply message structure:
	//  1. message type (1 byte)
	//  2. message id (8 bytes)
	//  3. header padding (1 byte)
	//  4. payload (n bytes, optional or at least 2 bytes)
	MinLenReplyUtf16 = int(10)

	// MinLenReplyError represents the minimum length
	// of error reply messages.
	// Error reply message structure:
	//  1. message type (1 byte)
	//  2. message id (8 bytes)
	//  3. error code length flag (1 byte, cannot be 0)
	//  4. error code (
	//    from 1 to 255 bytes,
	//    length must correspond to the length flag
	//  )
	//  5. error message (n bytes, UTF8 encoded, optional)
	MinLenReplyError = int(11)

	// MinLenRequestRestoreSession represents the minimum length
	// of session restoration request messages.
	// Session restoration request message structure:
	//  1. message type (1 byte)
	//  2. message id (8 bytes)
	//  3. session key (n bytes, 7-bit ASCII encoded, at least 1 byte)
	MinLenRequestRestoreSession = int(10)

	// MinLenDoCloseSession represents the minimum length
	// of session destruction request messages.
	// Session destruction request message structure:
	//  1. message type (1 byte)
	//  2. message id (8 bytes)
	MinLenDoCloseSession = int(9)

	// MinLenNotifySessionCreated represents the minimum length
	// of session creation notification messages.
	// Session creation notification message structure:
	//  1. message type (1 byte)
	//  2. session key (n bytes, 7-bit ASCII encoded, at least 1 byte)
	MinLenNotifySessionCreated = int(2)

	// MinLenNotifySessionClosed represents the minimum length
	// of session creation notification messages.
	// Session destruction notification message structure:
	//  1. message type (1 byte)
	MinLenNotifySessionClosed = int(1)

	// MinLenAcceptConf represents the minimum length
	// of an endpoint metadata message.
	//  1. message type (1 byte)
	//  2. major protocol version (1 byte)
	//  3. minor protocol version (1 byte)
	//  4. read timeout in milliseconds (4 byte)
	//  5. message buffer size in bytes (4 byte)
	//  6. sub-protocol name (0+ bytes)
	MinLenAcceptConf = int(11)
)
View Source
const (

	// MsgReplyError is a request reply sent only by the server and represents
	// an error-reply to a previously sent request
	MsgReplyError = byte(0)

	// MsgReplyShutdown is a request reply sent only by the server when a
	// request is received during server shutdown and can't therefore be
	// processed
	MsgReplyShutdown = byte(1)

	// MsgReplyInternalError is a request reply sent only by the server if an
	// unexpected internal error arose during the processing of a request
	MsgReplyInternalError = byte(2)

	// MsgReplySessionNotFound is a session restoration request reply sent only
	// by the server when the requested session was not found
	MsgReplySessionNotFound = byte(3)

	// MsgReplyMaxSessConnsReached is session restoration request reply sent
	// only by the server when the maximum number of concurrent connections for
	// a the requested session was reached
	MsgReplyMaxSessConnsReached = byte(4)

	// MsgReplySessionsDisabled is session restoration request reply sent only
	// by the server when sessions are disabled
	MsgReplySessionsDisabled = byte(5)

	// MsgNotifySessionCreated is a notification signal sent only by the server
	// to notify the client about the creation of a session
	MsgNotifySessionCreated = byte(21)

	// MsgNotifySessionClosed is a notification signal sent only by the server
	// to notify the client about the closure of the currently active session
	MsgNotifySessionClosed = byte(22)

	// MsgAcceptConf is a connection approval push-message sent only by the
	// server right after the handshake and includes the server configurations
	MsgAcceptConf = byte(23)

	// MsgRequestCloseSession is session closure command sent only by the client to
	// make the server close the currently active session
	MsgRequestCloseSession = byte(31)

	// MsgRequestRestoreSession is a session restoration request sent only by
	// the client
	MsgRequestRestoreSession = byte(32)

	// MsgHeartbeat is sent only by the client to acknowledge the server about
	// the activity of the connection to prevent it from shutting the connection
	// down on read timeout
	MsgHeartbeat = byte(33)

	// MsgSignalBinary represents a signal with binary payload
	MsgSignalBinary = byte(63)

	// MsgSignalUtf8 represents a signal with UTF8 encoded payload
	MsgSignalUtf8 = byte(64)

	// MsgSignalUtf16 represents a signal with UTF16 encoded payload
	MsgSignalUtf16 = byte(65)

	// MsgRequestBinary represents a request with binary payload
	MsgRequestBinary = byte(127)

	// MsgRequestUtf8 represents a request with a UTF8 encoded payload
	MsgRequestUtf8 = byte(128)

	// MsgRequestUtf16 represents a request with a UTF16 encoded payload
	MsgRequestUtf16 = byte(129)

	// MsgReplyBinary represents a reply with a binary payload
	MsgReplyBinary = byte(191)

	// MsgReplyUtf8 represents a reply with a UTF8 encoded payload
	MsgReplyUtf8 = byte(192)

	// MsgReplyUtf16 represents a reply with a UTF16 encoded payload
	MsgReplyUtf16 = byte(193)
)

Variables

This section is empty.

Functions

func CalcMsgLenRequest

func CalcMsgLenRequest(
	name []byte,
	encoding pld.Encoding,
	payload []byte,
) int

CalcMsgLenRequest returns the size of a request message with the given name and payload

func CalcMsgLenSignal

func CalcMsgLenSignal(
	name []byte,
	encoding pld.Encoding,
	payload []byte,
) int

CalcMsgLenSignal returns the size of a signal message with the given name and payload

func NewAcceptConfMessage

func NewAcceptConfMessage(conf ServerConfiguration) ([]byte, error)

NewAcceptConfMessage composes a server configuration message and writes it to the given buffer

func WriteMsgHeartbeat

func WriteMsgHeartbeat(writer io.WriteCloser) error

WriteMsgHeartbeat writes a session closure notification message to the given writer closing it eventually

func WriteMsgNamelessRequest

func WriteMsgNamelessRequest(
	writer io.WriteCloser,
	reqType byte,
	identifier []byte,
	binaryPayload []byte,
) error

WriteMsgNamelessRequest writes a nameless (initially without a name) request message to the given writer closing it eventually

func WriteMsgNotifySessionClosed

func WriteMsgNotifySessionClosed(writer io.WriteCloser) error

WriteMsgNotifySessionClosed writes a session closure notification message to the given writer closing it eventually

func WriteMsgNotifySessionCreated

func WriteMsgNotifySessionCreated(
	writer io.WriteCloser,
	sessionInfo []byte,
) error

WriteMsgNotifySessionCreated writes a session creation notification message to the given writer closing it eventually

func WriteMsgReply

func WriteMsgReply(
	writer io.WriteCloser,
	requestIdentifier []byte,
	payloadEncoding pld.Encoding,
	payloadData []byte,
) error

WriteMsgReply writes a reply message to the given writer closing it eventually

func WriteMsgReplyError

func WriteMsgReplyError(
	writer io.WriteCloser,
	requestIdent []byte,
	code,
	message []byte,
	safeMode bool,
) error

WriteMsgReplyError writes an error reply message to the given writer closing it eventually

func WriteMsgRequest

func WriteMsgRequest(
	writer io.WriteCloser,
	identifier []byte,
	name []byte,
	payloadEncoding pld.Encoding,
	payloadData []byte,
	safeMode bool,
) error

WriteMsgRequest writes a named request message to the given writer closing it eventually

func WriteMsgSignal

func WriteMsgSignal(
	writer io.WriteCloser,
	name []byte,
	payloadEncoding pld.Encoding,
	payloadData []byte,
	safeMode bool,
) error

WriteMsgSignal writes a named signal message to the given writer closing it eventually

func WriteMsgSpecialRequestReply

func WriteMsgSpecialRequestReply(
	writer io.WriteCloser,
	reqType byte,
	reqIdent []byte,
) error

WriteMsgSpecialRequestReply writes a special request reply message to the given writer closing it eventually

Types

type Buffer

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

Buffer represents a message buffer

func (*Buffer) Bytes

func (buf *Buffer) Bytes() []byte

Bytes returns a full-length slice of the buffer

func (*Buffer) Close

func (buf *Buffer) Close()

Close resets the message buffer and puts it back into the original pool

func (*Buffer) Data

func (buf *Buffer) Data() []byte

Data returns a slice of the usable part of the buffer

func (*Buffer) IsEmpty

func (buf *Buffer) IsEmpty() bool

IsEmpty returns true if the buffer is empty, otherwise returns false

func (*Buffer) Read

func (buf *Buffer) Read(reader io.Reader) error

Read reads from the given reader until EOF or error

type Message

type Message struct {
	MsgBuffer          Buffer
	MsgType            byte
	MsgIdentifier      [8]byte
	MsgIdentifierBytes []byte
	MsgName            []byte
	MsgPayload         pld.Payload

	// ServerConfiguration is only initialized for MsgAcceptConf type messages
	ServerConfiguration ServerConfiguration
	// contains filtered or unexported fields
}

Message represents a non-thread-safe WebWire protocol message

func NewMessage

func NewMessage(bufferSize uint32) *Message

NewMessage creates a new buffered message instance

func (*Message) Close

func (msg *Message) Close()

Close implements the Message interface

func (*Message) Identifier

func (msg *Message) Identifier() [8]byte

Identifier implements the Message interface

func (*Message) Name

func (msg *Message) Name() []byte

Name implements the Message interface

func (*Message) Payload

func (msg *Message) Payload() []byte

Payload implements the Message interface

func (*Message) PayloadEncoding

func (msg *Message) PayloadEncoding() pld.Encoding

PayloadEncoding implements the Message interface

func (*Message) PayloadUtf8

func (msg *Message) PayloadUtf8() ([]byte, error)

PayloadUtf8 implements the Message interface

func (*Message) Read

func (msg *Message) Read(reader io.Reader) (typeParsed bool, err error)

Read reads and parses the message from the given reader

func (*Message) ReadBytes

func (msg *Message) ReadBytes(bytes []byte) (typeParsed bool, err error)

ReadBytes reads and parses the message from the given byte slice

func (*Message) RequiresReply

func (msg *Message) RequiresReply() bool

RequiresReply returns true if a message of this type requires a reply, otherwise returns false.

type Pool

type Pool interface {
	// Get fetches a message buffer from the pool which must be put back when
	// it's no longer needed
	Get() *Message
}

Pool defines the message buffer pool interface

type ServerConfiguration

type ServerConfiguration struct {
	MajorProtocolVersion byte
	MinorProtocolVersion byte
	SubProtocolName      []byte
	ReadTimeout          time.Duration
	MessageBufferSize    uint32
}

ServerConfiguration represents the MsgAcceptConf payload data

type SyncPool

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

SyncPool represents a thread-safe messageBuffer pool

func NewSyncPool

func NewSyncPool(bufferSize, prealloc uint32) *SyncPool

NewSyncPool initializes a new sync.Pool based message buffer pool instance

func (*SyncPool) Get

func (mbp *SyncPool) Get() *Message

Get implements the Pool interface

Jump to

Keyboard shortcuts

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