Documentation ¶
Overview ¶
* Package control includes the code to implement and use the control protocol.
This package and the child packages are highly EXPERIMENTAL and they might break any time. Use with CAUTION.
Index ¶
Constants ¶
const AckOpCode = OpCode(^uint8(0))
const ( // ActualProtocolVersion is the supported protocol version, and the default one used to send outbound messages ActualProtocolVersion uint8 = 0 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection interface { // WriteMessage writes a message to the wire. // This method may not perform the actual writing, but it could just add the message to a local queue, which then dispatch the actual message. WriteMessage(msg *Message) // ReadMessage reads a message from the wire. // This blocks until there's a message available to read. // Returns nil if the Connection is closed. ReadMessage() *Message // Errors returns a channel that signals very bad, usually fatal, errors // (like cannot re-establish the connection after several attempts) Errors() <-chan error }
Connection handles the low level stuff, reading and writing to the wire
type ErrorHandler ¶
ErrorHandler is an error handler for the Service interface
type ErrorHandlerFunc ¶
func (ErrorHandlerFunc) HandleServiceError ¶
func (c ErrorHandlerFunc) HandleServiceError(ctx context.Context, err error)
type Message ¶
type Message struct { MessageHeader // contains filtered or unexported fields }
Message is a MessageHeader and a payload
func NewMessage ¶
func NewMessage(uuid [16]byte, opcode uint8, payload []byte, opts ...MessageOpt) Message
NewMessage creates a new message.
type MessageFlag ¶
type MessageFlag uint8
type MessageHandler ¶
type MessageHandler interface {
HandleServiceMessage(ctx context.Context, message ServiceMessage)
}
MessageHandler is an error handler for ServiceMessage. Every implementation should invoke message.Ack() when the Service can ack back to the other end of the connection.
type MessageHandlerFunc ¶
type MessageHandlerFunc func(ctx context.Context, message ServiceMessage)
func (MessageHandlerFunc) HandleServiceMessage ¶
func (c MessageHandlerFunc) HandleServiceMessage(ctx context.Context, message ServiceMessage)
type MessageHeader ¶
type MessageHeader struct {
// contains filtered or unexported fields
}
MessageHeader represents a message header
+---------+---------+-------+----------+--------+ | | 0-8 | 8-16 | 16-24 | 24-32 | +---------+---------+-------+----------+--------+ | 0-32 | version | flags | <unused> | opcode | +---------+---------+-------+----------+--------+ | 32-64 | uuid[0:4] | +---------+-------------------------------------+ | 64-96 | uuid[4:8] | +---------+-------------------------------------+ | 96-128 | uuid[8:12] | +---------+-------------------------------------+ | 128-160 | uuid[12:16] | +---------+-------------------------------------+ | 160-192 | length | +---------+-------------------------------------+
func (MessageHeader) Check ¶
func (m MessageHeader) Check(flag MessageFlag) bool
Check returns true if the flag is 1, false otherwise
func (MessageHeader) Length ¶
func (m MessageHeader) Length() uint32
UUID returns the payload length
func (MessageHeader) OpCode ¶
func (m MessageHeader) OpCode() uint8
OpCode returns the opcode of the message
func (MessageHeader) Version ¶
func (m MessageHeader) Version() uint8
Version returns the protocol version
type MessageOpt ¶
type MessageOpt func(*Message)
MessageOpt is an additional option for NewMessage
func WithFlags ¶
func WithFlags(flags uint8) MessageOpt
WithVersion specifies the flags to use when creating a new Message
func WithVersion ¶
func WithVersion(version uint8) MessageOpt
WithVersion specifies the version to use when creating a new Message
type Service ¶
type Service interface { // SendAndWaitForAck sends a message to the other end and waits for the ack SendAndWaitForAck(opcode OpCode, payload encoding.BinaryMarshaler) error // MessageHandler sets a MessageHandler to this service. // This method is non blocking, because a polling loop is already running inside. MessageHandler(handler MessageHandler) // ErrorHandler sets a ErrorHandler to this service. // This method is non blocking, because a polling loop is already running inside. ErrorHandler(handler ErrorHandler) }
Service is the high level interface that handles send with retries and acks
type ServiceMessage ¶
type ServiceMessage struct {
// contains filtered or unexported fields
}
func NewServiceMessage ¶
func NewServiceMessage(inboundMessage *Message, ackFunc func(err error)) ServiceMessage
func (ServiceMessage) Ack ¶
func (c ServiceMessage) Ack()
Ack this message to the other end of the connection.
func (ServiceMessage) AckWithError ¶
func (c ServiceMessage) AckWithError(err error)
Ack this message to the other end of the connection, propagating an error while handling this message.
func (ServiceMessage) Headers ¶
func (c ServiceMessage) Headers() MessageHeader
func (ServiceMessage) Payload ¶
func (c ServiceMessage) Payload() []byte
type ServiceWrapper ¶
ServiceWrapper wraps a service in another service to offer additional functionality