Documentation
¶
Overview ¶
Package cobs implements Consistent Overhead Byte Stuffing (COBS) encoding and decoding algorithms for efficient, reliable and unambiguous packet framing.
Index ¶
Constants ¶
const (
Delimiter = byte(0x00) // default packet framing delimiter.
)
Variables ¶
var EOD = errors.New("EOD")
EOD is the error returned when decoding and a delimiter was written. Functions return EOD to signal a graceful end of a frame.
var ErrIncompleteFrame = errors.New("frame incomplete")
ErrIncompleteData means a decoder was closed with an incomplete frame.
var ErrUnexpectedEOD = errors.New("unexpected EOD")
ErrUnexpectedEOD means that a delimiter was encountered in a malformed frame.
Functions ¶
func WithDelimiterOnClose ¶ added in v1.2.0
func WithDelimiterOnClose(enabled bool) option
WithDelimiterOnClose configures the encoder to append a sentinel delimiter on close.
func WithReduced ¶ added in v1.2.0
func WithReduced(enabled bool) option
WithReduced configures the encoder/decoder to run COBS/R.
func WithSentinel ¶ added in v1.2.0
func WithSentinel(sentinel byte) option
WithSentinel configures the encoder/decoder to use a custom sentinel value.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
A Decoder implements the io.Writer and io.ByteWriter interfaces. Data written will we be decoded and forwarded byte per byte.
func NewDecoder ¶
NewDecoder returns a Decoder that writes decoded data to w.
func (*Decoder) Close ¶ added in v1.2.0
Close flushes the last byte in case of COBS reduced (COBS/R) and will return an error if the decoder expects more data.
func (*Decoder) NeedsMoreData ¶ added in v1.1.0
NeedsMoreData returns true if the decoder needs more data for a full frame.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
An Encoder implements the io.Writer and io.ByteWriter interfaces. Data written will we be encoded into groups and forwarded.
func NewEncoder ¶
NewEncoder returns an Encoder that writes encoded data to w.
func (*Encoder) Close ¶
Close has to be called after writing a full frame and will write the last group.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
decode
command
Decode reads from standard input, and writes the decoded data to standard output.
|
Decode reads from standard input, and writes the decoded data to standard output. |
|
encode
command
Encode reads from standard input, and writes the encoded data to standard output.
|
Encode reads from standard input, and writes the encoded data to standard output. |