Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Adapter ¶
type Adapter interface { // Given a payload, wrap it in the appropriate envelope Wrap([]byte) ([]byte, error) // Given a complete message, strip and verify expected envelope Unwrap([]byte) ([]byte, error) // Given a sample payload size, calculate the expected length of the wrapped message MessageSize(int) (int, error) }
Objects that implement this interface are used as middleware while sending and receiving messages. Typically this is used in support of symmetric capabilities such as CRC checksums or Reed Solomon parity bytes.
type FrameConfig ¶
type FrameConfig struct { // Byte sequence that designates the start of a // message frame. FrameSyncMarker []byte // Size of fully encoded messages to be transmitted or // received. It is assumed that either a consant message // size will be used, or some sort of padding will be // applied by an included Adapter. This value does NOT // include the length of the sync marker. FrameSize int // Adapters apply basic encoding/decoding capabilities // to as messages are converted to and from frames. Adapters []Adapter }
func (*FrameConfig) Err ¶
func (cfg *FrameConfig) Err() error
type FrameReceiver ¶
type FrameReceiver struct {
// contains filtered or unexported fields
}
func NewFrameReceiver ¶
func NewFrameReceiver(cfg FrameConfig, src io.Reader) (*FrameReceiver, error)
func (*FrameReceiver) Receive ¶
func (r *FrameReceiver) Receive(ctx context.Context, msgC chan<- []byte, errC chan<- error)
Forward received frames to provided channel. This function is designed to be called within a goroutine. A caller must use Receive to actually start reading from the source.
A call to Receive will continue until the upstream source is depleted, indicated by an io.EOF error. A user may also cancel the Receive operation prematurely by closing the provided Context.
If a caller provides a non-nil error channel, any errors encountered within the frame processor will be sent to it. This channel is used synchronously, so a caller MUST read from it to unblock frame reception following an error.
type FrameSender ¶
type FrameSender struct {
// contains filtered or unexported fields
}
func NewFrameSender ¶
func NewFrameSender(cfg FrameConfig, dst io.Writer) (*FrameSender, error)
func (*FrameSender) Send ¶
func (s *FrameSender) Send(msg []byte) error