Expand description
§COBSIN - COBS In-Place Encoding/Decoding
This library provides in-place COBS (Consistent Overhead Byte Stuffing) encoding
and decoding for no_std environments.
§Overview
COBS is an algorithm that transforms data to eliminate zero bytes, making it suitable for packet-based protocols where zeros are used as delimiters.
§Features
no_stdcompatible - works in embedded and bare-metal environments- In-place encoding and decoding - minimal memory overhead
- Zero allocations - no heap required
§Functions
cobs_encode_in_place- Encode data in-place, returning the new lengthcobs_decode_in_place- Decode COBS data in-place, returning the original lengthmax_overhead- Calculate maximum overhead for a given buffer sizerequired_buf_len- Calculate the required buffer size for encoding
§Example
use cobsin::{cobs_encode_in_place, cobs_decode_in_place};
let data = *b"Hello\x00World";
let input_len = data.len();
// Buffer must be large enough: use a fixed-size array or Vec
let mut buf = [0u8; 32];
buf[..input_len].copy_from_slice(&data);
// Encode
let encoded_len = cobs_encode_in_place(&mut buf, input_len).unwrap();
// Decode
let decoded_len = cobs_decode_in_place(&mut buf, encoded_len).unwrap();
assert_eq!(&buf[..decoded_len], b"Hello\x00World");Enums§
Functions§
- cobs_
decode_ in_ place - Decodes COBS-encoded data in-place, reversing the encoding process.
- cobs_
encode_ in_ place - Encodes data in-place using COBS (Consistent Overhead Byte Stuffing) algorithm.
- max_
overhead - required_
buf_ len