Giter Site home page Giter Site logo

simple_slip's Introduction

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);

simple_slip's People

Contributors

sam-peach avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.