Documentation ¶
Index ¶
Constants ¶
const ( HeaderControlEcho = 0x00 HeaderControlPauseStream = 0x01 HeaderControlResumeStream = 0x02 )
Control signal types
const ( StreamHeaderMaxLength = 0x1fff StreamHeaderMaxMarker = 0x07 )
Stream header consts
const (
HeaderMaxData = 0x3f
)
Consts
const (
MaxCommandID = 0x0f
)
Consts
Variables ¶
var ( ErrHandlerUnknownHeaderType = errors.New( "unknown command header type") ErrHandlerControlMessageTooLong = errors.New( "control message was too long") ErrHandlerInvalidControlMessage = errors.New( "invalid control message") )
Errors
var ( ErrStreamsInvalidStreamID = errors.New( "stream ID is invalid") ErrStreamsStreamOperateInactiveStream = errors.New( "specified stream was inactive for operation") ErrStreamsStreamClosingInactiveStream = errors.New( "closing an inactive stream is not allowed") ErrStreamsStreamReleasingInactiveStream = errors.New( "releasing an inactive stream is not allowed") )
Errors
var (
ErrCommandRunUndefinedCommand = errors.New(
"undefined Command")
)
Errors
var (
ErrFSMMachineClosed = errors.New(
"FSM Machine is already closed, it cannot do anything but be released")
)
Errors
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder builds a command
func Register ¶
func Register(name string, c Command, p configuration.PresetReloader) Builder
Register builds a Builder for registration
type Command ¶
type Command func( l log.Logger, w StreamResponder, cfg Configuration, ) FSMMachine
Command represents a command handler machine builder
type Commander ¶
type Commander struct {
// contains filtered or unexported fields
}
Commander command control
type Commands ¶
type Commands [MaxCommandID + 1]Builder
Commands contains data of all commands
func (Commands) Reconfigure ¶
func (c Commands) Reconfigure( p []configuration.Preset, ) ([]configuration.Preset, error)
Reconfigure lets commands reset configuration
func (*Commands) Register ¶
func (c *Commands) Register( id byte, name string, cb Command, ps configuration.PresetReloader, )
Register registers a new command
func (Commands) Run ¶
func (c Commands) Run( id byte, l log.Logger, w StreamResponder, cfg Configuration, ) (FSM, error)
Run creates command executer
type Configuration ¶
Configuration contains configuration data needed to run command
type FSMError ¶
type FSMError struct {
// contains filtered or unexported fields
}
FSMError Represents an error from FSM
func NoFSMError ¶
func NoFSMError() FSMError
NoFSMError return a FSMError that represents a success operation
func ToFSMError ¶
func ToFSMError(e error, c StreamError) FSMError
ToFSMError converts error to FSMError
type FSMMachine ¶
type FSMMachine interface { // Bootup boots up the machine Bootup(r *rw.LimitedReader, b []byte) (FSMState, FSMError) // Close stops the machine and get it ready for release. // // NOTE: Close function is responsible in making sure the HeaderClose signal // is sent before it returns. // (It may not need to send the header by itself, but it have to // make sure the header is sent) Close() error // Release shuts the machine down completely and release it's resources Release() error }
FSMMachine State machine
type FSMState ¶
type FSMState func(f *FSM, r *rw.LimitedReader, h StreamHeader, b []byte) error
FSMState represents a state of a machine
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler client stream control
type HandlerCancelSignal ¶
type HandlerCancelSignal chan struct{}
HandlerCancelSignal signals the cancel of the entire handling proccess
type Header ¶
type Header byte
Header Packet Type
const ( // 00------: Control signals // Remaing bits: Data length // // Format: // 0011111 [63 bytes long data] - 63 bytes of control data // HeaderControl Header = 0x00 // 01------: Bidirectional stream data // Remaining bits: Stream ID // Followed by: Parameter or data // // Format: // 0111111 [Command parameters / data] - Open/use stream 63 to execute // command or transmit data HeaderStream Header = 0x40 // 10------: Close stream // Remaining bits: Stream ID // // Format: // 1011111 - Close stream 63 // // WARNING: The requester MUST NOT send any data to this stream once this // header is sent. // // WARNING: The receiver MUST reply with a Completed header to indicate // the success of the Close action. Until a Completed header is // replied, all data from the sender must be proccessed as normal. HeaderClose Header = 0x80 // 11------: Stream has been closed/completed in respond to client request // Remaining bits: Stream ID // // Format: // 1111111 - Stream 63 is completed // // WARNING: This header can ONLY be send in respond to a Close header // // WARNING: The sender of this header MUST NOT send any data to the stream // once this header is sent until this stream been re-opened by a // Data header HeaderCompleted Header = 0xc0 )
Packet Types
func (Header) IsStreamControl ¶
IsStreamControl returns true when the header is for stream control, false when otherwise
type StreamError ¶
type StreamError uint16
StreamError Stream Error signal
const ( StreamErrorCommandUndefined StreamError = 0x01 StreamErrorCommandFailedToBootup StreamError = 0x02 )
Error signals
type StreamHeader ¶
type StreamHeader [2]byte
StreamHeader contains data of the stream header
func (StreamHeader) Length ¶
func (s StreamHeader) Length() uint16
Length returns the data length of the stream
func (StreamHeader) Marker ¶
func (s StreamHeader) Marker() byte
Marker returns the header marker data
func (*StreamHeader) Set ¶
func (s *StreamHeader) Set(marker byte, n uint16)
Set sets the stream header
type StreamInitialSignalSender ¶
type StreamInitialSignalSender struct {
// contains filtered or unexported fields
}
StreamInitialSignalSender sends stream initial signal
func (*StreamInitialSignalSender) Signal ¶
func (s *StreamInitialSignalSender) Signal( errno StreamError, success bool) error
Signal send signal
type StreamResponder ¶
type StreamResponder struct {
// contains filtered or unexported fields
}
StreamResponder sends data through stream
func (StreamResponder) HeaderSize ¶
func (w StreamResponder) HeaderSize() int
HeaderSize returns the size of header
func (StreamResponder) Send ¶
func (w StreamResponder) Send(marker byte, data []byte, buf []byte) error
Send sends data. Data will be automatically segmentated if it's too long to fit into one data package or buffer space
func (StreamResponder) SendManual ¶
func (w StreamResponder) SendManual(marker byte, data []byte) error
SendManual sends the data without automatical segmentation. It will construct the data package directly using the given `data` buffer, that is, the first n bytes of the given `data` will be used to setup headers. It is the caller's
responsibility to leave n bytes of space so no meaningful data will be over
written. The number n can be acquired by calling .HeaderSize() method.
func (StreamResponder) Signal ¶
func (w StreamResponder) Signal(signal Header) error
Signal sends a signal