1
Fork 0

WIP on decode tool.

Issue #9.
This commit is contained in:
Alex Helfet 2017-12-27 13:35:00 +00:00
parent ca85eb84bb
commit ce3ea885d9
15 changed files with 431 additions and 39 deletions

1
.gitignore vendored
View file

@ -1,3 +1,2 @@
target/
Cargo.lock
.cargo/config

254
Cargo.lock generated Normal file
View file

@ -0,0 +1,254 @@
[[package]]
name = "ansi_term"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "atty"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "case"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "clap"
version = "2.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
"atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cobs"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "derive-error"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"case 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "encode_unicode"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "framed"
version = "0.1.4"
dependencies = [
"cobs 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"ref_slice 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
"ssmarshal 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "framed_decode"
version = "0.1.0"
dependencies = [
"clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)",
"derive-error 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"framed 0.1.4",
"framed_test_type 0.1.0",
]
[[package]]
name = "framed_test_type"
version = "0.1.0"
dependencies = [
"framed 0.1.4",
"serde 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.2.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "quote"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_syscall"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_termios"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ref_slice"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
version = "1.0.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_derive"
version = "1.0.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive_internals 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_derive_internals"
version = "0.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
"synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ssmarshal"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"encode_unicode 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "strsim"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "syn"
version = "0.11.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "synom"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termion"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "textwrap"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-width"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-xid"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "vec_map"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6b3568b48b7cefa6b8ce125f9bb4989e52fbcc29ebea88df04cc7c5f12f70455"
"checksum atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8352656fd42c30a0c3c89d26dea01e3b77c0ab2af18230835c15e2e13cd51859"
"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf"
"checksum case 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e88b166b48e29667f5443df64df3c61dc07dc2b1a0b0d231800e07f09a33ecc1"
"checksum clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)" = "110d43e343eb29f4f51c1db31beb879d546db27998577e5715270a54bcf41d3f"
"checksum cobs 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "98acedfd5fc3ef93c4c844980f30318a445c24f76863a9e51f0599b9f1d274ad"
"checksum derive-error 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ec098440b29ea3b1ece3e641bac424c19cf996779b623c9e0f2171495425c2c8"
"checksum encode_unicode 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c088ec0ed2282dcd054f2c124c0327f953563e6c75fdc6ff5141779596289830"
"checksum libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)" = "36fbc8a8929c632868295d0178dd8f63fc423fd7537ad0738372bd010b3ac9b0"
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "ab105df655884ede59d45b7070c8a65002d921461ee813a024558ca16030eea0"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum ref_slice 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "825740057197b7d43025e7faf6477eaabc03434e153233da02d1f44602f71527"
"checksum serde 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "386122ba68c214599c44587e0c0b411e8d90894503a95425b4f9508e4317901f"
"checksum serde_derive 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "ec0bfa6c5784e7d110514448da0e1dbad41ea5514c3e68be755b23858b83a399"
"checksum serde_derive_internals 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)" = "730fe9f29fe8db69a601837f416e46cba07792031ed6b27557a43e49d62d89ae"
"checksum ssmarshal 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f3e6ad23b128192ed337dfa4f1b8099ced0c2bf30d61e551b65fda5916dbb850"
"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
"checksum textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0b59b6b4b44d867f1370ef1bd91bfb262bf07bf0ae65c202ea2fbc16153b693"
"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f"
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
"checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c"
"checksum winapi 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "890b38836c01d72fdb636d15c9cfc52ec7fd783b330abc93cd1686f4308dfccc"
"checksum winapi-i686-pc-windows-gnu 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ca38ad0b1b8fcebdf9a7906e368ce3a760ffa638c4c4f0cb57f3c26ad34cc86e"
"checksum winapi-x86_64-pc-windows-gnu 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a824ed89cff621305f4ae379551c65e1fca1eadb1d4a25e3a4e8989080a2d337"

View file

@ -1,36 +1,6 @@
[package]
name = "framed"
version = "0.1.4"
description = "Send and receive data over lossy streams of bytes."
authors = ["Alex Helfet <alex.helfet@gmail.com>"]
categories = ["no-std", "embedded", "encoding", "network-programming"]
keywords = ["no_std", "networking", "datalink", "protocol", "embedded"]
readme = "README.md"
license = "MIT OR Apache-2.0"
repository = "https://github.com/fluffysquirrels/framed-rs"
[badges.travis-ci]
repository = "fluffysquirrels/framed-rs"
branch = "master"
[dependencies]
cobs = "^0.1.3"
ref_slice = "^1.1.1"
serde = { version = "^1.0", optional = true }
ssmarshal = { version = "^1.0", optional = true }
[dev-dependencies]
serde_derive = "^1.0"
[features]
default = ["use_std", "typed"]
# Enable to print all data to stdout for testing.
trace = []
# Use standard library. Enabled by default, disable for no_std.
use_std = []
# Enables the `typed` sub-module for sending and receiving
# structs serialized with serde.
typed = ["serde", "ssmarshal"]
[workspace]
members = [
"framed",
"decode",
"test_type",
]

32
decode/Cargo.toml Normal file
View file

@ -0,0 +1,32 @@
[package]
name = "framed_decode"
version = "0.1.0"
authors = ["Alex Helfet <alex.helfet@gmail.com>"]
description = """Send and receive data over lossy streams of bytes.
TODO.
"""
categories = ["no-std", "embedded", "encoding", "network-programming"]
keywords = ["no_std", "networking", "datalink", "protocol", "embedded"]
readme = "../README.md"
license = "MIT OR Apache-2.0"
repository = "https://github.com/fluffysquirrels/framed-rs"
[badges.travis-ci]
repository = "fluffysquirrels/framed-rs"
branch = "master"
[dependencies]
clap = "^2.29.0"
derive-error = "^0.0.4"
framed = { path = "../framed" }
framed_test_type = { path = "../test_type" }
[features]
default = ["typed"]
# Enable to print all data to stdout for testing.
trace = ["framed/trace"]
# TODO.
typed = ["framed/typed"]

5
decode/src/dynamic.rs Normal file
View file

@ -0,0 +1,5 @@
// TODO: Generate this.
extern crate framed_test_type;
use framed_test_type::Test as UserType;
static USER_TYPE_NAME: &'static str = "framed_test_type::Test";

11
decode/src/error.rs Normal file
View file

@ -0,0 +1,11 @@
use framed;
use std;
#[derive(Debug, Error)]
pub enum Error {
/// Error in library `framed`.
#[error(non_std)]
Framed(framed::Error),
}
pub type Result<T> = std::result::Result<T, Error>;

35
decode/src/main.rs Normal file
View file

@ -0,0 +1,35 @@
#![deny(warnings)]
#[macro_use]
extern crate clap;
#[macro_use]
extern crate derive_error;
extern crate framed;
include!("dynamic.rs");
mod error;
use error::Result;
// use clap::{App, Arg};
use framed::typed::Receiver;
use std::io::stdin;
fn main() {
match try() {
Ok(()) => (),
Err(e) => eprintln!("Error: {}\n\
Detail: {:#?}", e, e),
};
}
fn try() -> Result<()> {
let app = app_from_crate!();
let _matches = app.get_matches();
let mut r = Receiver::<_, UserType>::new(stdin());
loop {
let v = r.recv()?;
println!("Received value of type {}: {:#?}", USER_TYPE_NAME, v);
}
}

36
framed/Cargo.toml Normal file
View file

@ -0,0 +1,36 @@
[package]
name = "framed"
version = "0.1.4"
description = "Send and receive data over lossy streams of bytes."
authors = ["Alex Helfet <alex.helfet@gmail.com>"]
categories = ["no-std", "embedded", "encoding", "network-programming"]
keywords = ["no_std", "networking", "datalink", "protocol", "embedded"]
readme = "../README.md"
license = "MIT OR Apache-2.0"
repository = "https://github.com/fluffysquirrels/framed-rs"
[badges.travis-ci]
repository = "fluffysquirrels/framed-rs"
branch = "master"
[dependencies]
cobs = "^0.1.3"
ref_slice = "^1.1.1"
serde = { version = "^1.0", optional = true }
ssmarshal = { version = "^1.0", optional = true }
[dev-dependencies]
serde_derive = "^1.0"
[features]
default = ["use_std", "typed"]
# Enable to print all data to stdout for testing.
trace = []
# Use standard library. Enabled by default, disable for no_std.
use_std = []
# Enables the `typed` sub-module for sending and receiving
# structs serialized with serde.
typed = ["serde", "ssmarshal"]

View file

@ -11,8 +11,10 @@ use std::result;
#[cfg(not(feature = "use_std"))]
use core::result;
/// Type alias for results from this crate.
pub type Result<T> = result::Result<T, Error>;
/// Errors from this crate.
#[derive(Debug)]
pub enum Error {
/// COBS decode failed

View file

@ -102,8 +102,7 @@ extern crate ssmarshal;
pub mod channel;
pub mod error;
#[allow(unused_imports)]
use error::{Error, Result};
pub use error::{Error, Result};
#[cfg(all(feature = "typed", feature = "use_std"))]
pub mod typed;

19
test_type/Cargo.toml Normal file
View file

@ -0,0 +1,19 @@
[package]
name = "framed_test_type"
version = "0.1.0"
authors = ["Alex Helfet <alex.helfet@gmail.com>"]
description = "Send and receive data over lossy streams of bytes."
categories = ["no-std", "embedded", "encoding", "network-programming"]
keywords = ["no_std", "networking", "datalink", "protocol", "embedded"]
readme = "../README.md"
license = "MIT OR Apache-2.0"
repository = "https://github.com/fluffysquirrels/framed-rs"
[badges.travis-ci]
repository = "fluffysquirrels/framed-rs"
branch = "master"
[dependencies]
framed = { path = "../framed" }
serde = "^1.0"
serde_derive = "^1.0"

11
test_type/src/lib.rs Normal file
View file

@ -0,0 +1,11 @@
#![deny(warnings)]
extern crate serde;
#[macro_use]
extern crate serde_derive;
#[derive(Debug, Deserialize, Serialize)]
pub struct Test {
pub a: u32,
pub b: u16,
}

19
test_type/src/main.rs Normal file
View file

@ -0,0 +1,19 @@
#![deny(warnings)]
extern crate framed;
extern crate framed_test_type as lib;
use framed::typed::Sender;
use lib::Test;
use std::io::stdout;
fn main() {
let t = Test {
a: 1,
b: 2,
};
eprintln!("Sample value: {:#?}", t);
let mut s = Sender::<_, Test>::new(stdout());
s.send(&t).unwrap();
}