Documentation
¶
Overview ¶
Package cobs implements Consistent Overhead Byte Stuffing algorithm
COBS encoder breaks a packet into one or more sequences of non-zero bytes. The encoding routine searches through the first 254 bytes of the packet looking for the first occurrence of a zero byte. If no zero is found, then a code of 0xFF is output, followed by the 254 non-zero bytes. If a zero is found, then the number of bytes examined, n, is output as the code byte, followed by the actual values of the (n-1) non-zero bytes up to (but not including) the zero byte. This process is repeated until all the bytes of the packet have been encoded.
See also: http://www.stuartcheshire.org/papers/COBSforToN.pdf
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Encode ¶
Encode a null-terminated slice of bytes to a cobs frame
Example ¶
data := "Hello"
encoded := Encode(Terminate([]byte(data)))
fmt.Printf("%v: %v\n", data, encoded)
decoded := TrimNull(Decode(encoded))
fmt.Printf("%v: %v\n", encoded, string(decoded))
Output: Hello: [6 72 101 108 108 111] [6 72 101 108 108 111]: Hello
Types ¶
This section is empty.