Expand description
§cobs
This is an implementation of the Consistent Overhead Byte Stuffing (COBS) algorithm in Rust.
COBS is an algorithm for transforming a message into an encoding where a specific value (the “sentinel” value) is not used. This value can then be used to mark frame boundaries in a serial communication channel.
See the wikipedia article for details.
§Features
cobs
supports various runtime environments and is also suitable for no_std
environments.
§Default features
std
: Enables functionality relying on the standard library and also activates thealloc
feature. Currently only adds std::error::Error support for the library error types.alloc
: Enables features which operate on containers like alloc::vec::Vec. Enabled by thestd
feature.
§Optional features
Structs§
- Cobs
Decoder - The
CobsDecoder
type is used to decode a stream of bytes to a given mutable output slice. This is often useful when heap data structures are not available, or when not all message bytes are received at a single point in time. - Cobs
Encoder - The
CobsEncoder
type is used to encode a stream of bytes to a given mutable output slice. This is often useful when heap data structures are not available, or when not all message bytes are received at a single point in time. - Decode
Report - A report of the source and destination bytes used during in-place decoding
- Dest
BufToo Small Error - Encoder
State - The
EncoderState
is used to track the current state of a streaming encoder. This struct does not contain the output buffer (or a reference to one), and can be used when streaming the encoded output to a custom data type
Enums§
- Decode
Error - Decode
Result DecodeResult
represents the possible non-error outcomes of pushing an encoded data byte into theDecoderState
state machine- Decoder
State - The
DecoderState
is used to track the current state of a streaming decoder. This struct does not contain the output buffer (or a reference to one), and can be used when streaming the decoded output to a custom data type. - Push
Result PushResult
is used to represent the changes to an (encoded) output data buffer when an unencoded byte is pushed intoEncoderState
.
Functions§
- decode
- Decodes the
source
buffer into thedest
buffer. - decode_
in_ place - Decodes a message in-place.
- decode_
in_ place_ report - Decodes a message in-place.
- decode_
in_ place_ with_ sentinel - Decodes a message in-place using an arbitrary sentinel value.
- decode_
vec alloc
- Decodes the
source
buffer into a vector. - decode_
vec_ with_ sentinel alloc
- Decodes the
source
buffer into a vector with an arbitrary sentinel value. - decode_
with_ sentinel - Decodes the
source
buffer into thedest
buffer using an arbitrary sentinel value. - encode
- Encodes the
source
buffer into thedest
buffer. - encode_
vec alloc
- Encodes the
source
buffer into a vector, using the encode function. - encode_
vec_ with_ sentinel alloc
- Encodes the
source
buffer into a vector with an arbitrary sentinel value, using the encode_with_sentinel function. - encode_
with_ sentinel - Encodes the
source
buffer into thedest
buffer using an arbitrary sentinel value. - max_
encoding_ length - Calculates the maximum possible size of an encoded message given the length
of the source message. This may be useful for calculating how large the
dest
buffer needs to be in the encoding functions. - max_
encoding_ overhead - Calculates the maximum overhead when encoding a message with the given length. The overhead is a maximum of [n/254] bytes (one in 254 bytes) rounded up.
- try_
encode - Attempts to encode the
source
buffer into thedest
buffer.