From ce3ea885d9588117ced2e42f5cf0a2ace0975069 Mon Sep 17 00:00:00 2001 From: Alex Helfet Date: Wed, 27 Dec 2017 13:35:00 +0000 Subject: [PATCH] WIP on decode tool. Issue #9. --- .gitignore | 1 - Cargo.lock | 254 +++++++++++++++++++++++++++++++++ Cargo.toml | 42 +----- decode/Cargo.toml | 32 +++++ decode/src/dynamic.rs | 5 + decode/src/error.rs | 11 ++ decode/src/main.rs | 35 +++++ framed/Cargo.toml | 36 +++++ {src => framed/src}/channel.rs | 0 {src => framed/src}/error.rs | 2 + {src => framed/src}/lib.rs | 3 +- {src => framed/src}/typed.rs | 0 test_type/Cargo.toml | 19 +++ test_type/src/lib.rs | 11 ++ test_type/src/main.rs | 19 +++ 15 files changed, 431 insertions(+), 39 deletions(-) create mode 100644 Cargo.lock create mode 100644 decode/Cargo.toml create mode 100644 decode/src/dynamic.rs create mode 100644 decode/src/error.rs create mode 100644 decode/src/main.rs create mode 100644 framed/Cargo.toml rename {src => framed/src}/channel.rs (100%) rename {src => framed/src}/error.rs (93%) rename {src => framed/src}/lib.rs (99%) rename {src => framed/src}/typed.rs (100%) create mode 100644 test_type/Cargo.toml create mode 100644 test_type/src/lib.rs create mode 100644 test_type/src/main.rs diff --git a/.gitignore b/.gitignore index bfe3b6b..0a1f29a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ target/ -Cargo.lock .cargo/config \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..48e57cb --- /dev/null +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index 26d4236..bf5fded 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,36 +1,6 @@ -[package] -name = "framed" -version = "0.1.4" -description = "Send and receive data over lossy streams of bytes." -authors = ["Alex Helfet "] -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", +] \ No newline at end of file diff --git a/decode/Cargo.toml b/decode/Cargo.toml new file mode 100644 index 0000000..4e182e6 --- /dev/null +++ b/decode/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "framed_decode" +version = "0.1.0" +authors = ["Alex Helfet "] +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"] diff --git a/decode/src/dynamic.rs b/decode/src/dynamic.rs new file mode 100644 index 0000000..22adc20 --- /dev/null +++ b/decode/src/dynamic.rs @@ -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"; diff --git a/decode/src/error.rs b/decode/src/error.rs new file mode 100644 index 0000000..263e105 --- /dev/null +++ b/decode/src/error.rs @@ -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 = std::result::Result; diff --git a/decode/src/main.rs b/decode/src/main.rs new file mode 100644 index 0000000..cd5a8ca --- /dev/null +++ b/decode/src/main.rs @@ -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); + } +} diff --git a/framed/Cargo.toml b/framed/Cargo.toml new file mode 100644 index 0000000..9a3efb1 --- /dev/null +++ b/framed/Cargo.toml @@ -0,0 +1,36 @@ +[package] +name = "framed" +version = "0.1.4" +description = "Send and receive data over lossy streams of bytes." +authors = ["Alex Helfet "] +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"] diff --git a/src/channel.rs b/framed/src/channel.rs similarity index 100% rename from src/channel.rs rename to framed/src/channel.rs diff --git a/src/error.rs b/framed/src/error.rs similarity index 93% rename from src/error.rs rename to framed/src/error.rs index ddd22ec..b3ccef1 100644 --- a/src/error.rs +++ b/framed/src/error.rs @@ -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 = result::Result; +/// Errors from this crate. #[derive(Debug)] pub enum Error { /// COBS decode failed diff --git a/src/lib.rs b/framed/src/lib.rs similarity index 99% rename from src/lib.rs rename to framed/src/lib.rs index 12f2e34..d74b665 100644 --- a/src/lib.rs +++ b/framed/src/lib.rs @@ -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; diff --git a/src/typed.rs b/framed/src/typed.rs similarity index 100% rename from src/typed.rs rename to framed/src/typed.rs diff --git a/test_type/Cargo.toml b/test_type/Cargo.toml new file mode 100644 index 0000000..c18b6a5 --- /dev/null +++ b/test_type/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "framed_test_type" +version = "0.1.0" +authors = ["Alex Helfet "] +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" diff --git a/test_type/src/lib.rs b/test_type/src/lib.rs new file mode 100644 index 0000000..c7c9f8c --- /dev/null +++ b/test_type/src/lib.rs @@ -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, +} diff --git a/test_type/src/main.rs b/test_type/src/main.rs new file mode 100644 index 0000000..acbfd39 --- /dev/null +++ b/test_type/src/main.rs @@ -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(); +}