bsda

package
v0.0.0-...-8fa2440 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2016 License: MIT Imports: 5 Imported by: 2

Documentation

Overview

Package bsda provides message framing on top of ordered reliable byte streams.

The format is as follows:

Byte Stream Datagram Adaptation No. 1 (BSDA-1)
==============================================

Stream:
  Zero or more frames

Frame:
  4  ui  Data Length
...      Data

That is, each frame is a unsigned 32-bit integer indicating
the data length, followed by that many bytes of data.

All fields are little endian.

Index

Constants

This section is empty.

Variables

View Source
var ErrOversizeFrame = fmt.Errorf("received frame in excess of permitted size")
View Source
var ErrUnidirectional = fmt.Errorf("unidirectional stream")

Functions

This section is empty.

Types

type FrameReadWriter

type FrameReadWriter interface {
	FrameReader
	FrameWriter
}

type FrameReadWriterCloser

type FrameReadWriterCloser interface {
	FrameReadWriter
	Close() error
}

type FrameReader

type FrameReader interface {
	ReadFrame() ([]byte, error)
}

type FrameWriter

type FrameWriter interface {
	WriteFrame([]byte) error
}

type Stream

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

Bidirectional BSDA message stream.

func New

func New(stream io.ReadWriter) *Stream

Instantiates a new bidirectional BSDA message stream which provides framing on top of an underlying bytestream.

func NewReader

func NewReader(reader io.Reader) *Stream

Instantiates a new unidirectional BSDA message stream which provides framing on top of an underlying bytestream.

func NewWriter

func NewWriter(writer io.Writer) *Stream

Instantiates a new unidirectional BSDA message stream which provides framing on top of an underlying bytestream.

func (*Stream) Close

func (s *Stream) Close() error

Close the stream. If the underlying writer supports the io.Closer interface, it is closed as well.

func (*Stream) ReadFrame

func (s *Stream) ReadFrame() ([]byte, error)

Read a single frame. Underlying I/O errors are passed through.

Returns ErrOversizeFrame if the received frame exceeded MaxRxFrameSize. Calling this method again will skip such a frame's body and receive the next frame.

Do not call this method concurrently.

func (*Stream) SetMaxReadSize

func (s *Stream) SetMaxReadSize(sz int)

Set the maximum frame receive size in bytes.

Defaults to 32ki.

func (*Stream) WriteFrame

func (s *Stream) WriteFrame(buf []byte) error

Write a single frame. Underlying I/O errors are passed through.

Unlike ReadFrame, this method may be called concurrently.

Jump to

Keyboard shortcuts

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