#serial #slip

simple_slip

A small and simple library for SLIP encoding

3 releases

0.1.2 Sep 1, 2022
0.1.1 Sep 1, 2022
0.1.0 Aug 7, 2022

#1174 in Encoding

Download history 36/week @ 2024-07-27 46/week @ 2024-08-03 101/week @ 2024-08-10 21/week @ 2024-08-17 32/week @ 2024-08-24 25/week @ 2024-08-31 46/week @ 2024-09-07 1/week @ 2024-09-14 63/week @ 2024-09-21 84/week @ 2024-09-28 161/week @ 2024-10-05 13/week @ 2024-10-12 8/week @ 2024-10-19 32/week @ 2024-10-26 64/week @ 2024-11-02 70/week @ 2024-11-09

174 downloads per month

MIT/Apache

15KB
234 lines

Simple SLIP

A simple, lightweight implementation of RFC 1055 SLIP encoding for Rust!

What is SLIP encoding?

SLIP (serial line internet protocol) encoding is a very simple way of packaging so it can be transmitted to some other receiver. I'd highly recommend reading the Wikipedia article on the topic for some more insight!

Examples

SLIP is used in encoding data to be sent and decoding data to be read.

Encoding

NOTE: Each packet will start and end with an END (0xC0) byte.

use simple_slip::encode;

let input: Vec<u8> = vec![0x01, 0xDB, 0x49, 0xC0, 0x15];
let expected: Vec<u8> = vec![0xC0, 0x01, 0xDB, 0xDD, 0x49, 0xDB, 0xDC, 0x15, 0xC0];

let result: Vec<u8> = encode(&input).unwrap();

assert_eq!(result, expected);

Decoding

NOTE: Each packet will start decoding from the second occurrence of the END (0xC0) byte.

The following data array would only decode 0x01 as it's the only byte after the second END (0xC0) byte:

[0xA1, 0xA2, 0xA3, 0xC0, 0xC0, 0x01] --decode--> [0x01]
use simple_slip::decode;

let input: Vec<u8> = vec![0xA1, 0xA2, 0xA3, 0xC0, 0xC0, 0x01, 0xDB, 0xDD, 0x49, 0xDB, 0xDC, 0x15, 0xC0];
let expected: Vec<u8> = vec![0x01, 0xDB, 0x49, 0xC0, 0x15];

let result: Vec<u8> = decode(&input).unwrap();

assert_eq!(result, expected);

No runtime deps