From ed9e5da64809848c21b688dcf56c1fa417745a13 Mon Sep 17 00:00:00 2001 From: sergeych Date: Sat, 25 Nov 2023 03:01:02 +0300 Subject: [PATCH] docs --- README.md | 43 ++++++++++++++++++++++++++++++++----------- src/de.rs | 3 --- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index be09800..2b00b35 100644 --- a/README.md +++ b/README.md @@ -10,17 +10,41 @@ to replace older `Parsec` protocols family to cope with modern crazy world chall The most recent code will be there, and we encourage to use it also for issues/discussions. -> work in progress. +> Beta test -## Already implemented: +# Use as serde module: -The following parts are already safe to use +Use `bipack_ru:ser:to_bytes()` and `bipack_ru:de:from_bytes()` functions: +```rust +fn test() -> Result<(),Error> { + let src = HashSet::from(["foo", "bar", "buz"].map(|i| i.to_string())); + let packed = to_bytes(&src)?; + println!("{}", to_dump(&packed)); -- u8, u16, u32, u64, `smartint` variable-length unsigned -- i8, i16, i32, i64, `smartint` variable-length signed -- strings (utf8, variable length) -- fixed size byte arrays -- variable length byte arrays + let restored: HashSet = from_bytes(&packed)?; + println!("{:?}", restored); + assert_eq!(src, restored); +} +``` + + +serde module supports all Rust formats except floats/doubles which are not yet used and +standardised by bipack format. + +- All integers, signed and unsigned, are encoded with variable-length `smartint`. + +Fixed-size encoding is available using custom de/serializers (exactly as in postcard format): + +```rust +#[derive(Serialize)] +pub struct DefinitelyBigEndian { + #[serde(with = "bipack_ru::fixint::be")] + // or #[serde(with = "bipack_ru::fixint::le")] + x: u16, +} +``` + +## The sample code (see `src/lib.rs` for more:) ```rust @@ -39,9 +63,6 @@ fn test() { - `StringBuilder` super minimalistic string builder (footprint). -At the moment it does not include `serde` module as it is yet unclear how much -it will increase .wasm size. Could be added later. - The autodoc documentation is good enough already, so we do not repeat it here now. ## How to diff --git a/src/de.rs b/src/de.rs index 8918508..a6dcc82 100644 --- a/src/de.rs +++ b/src/de.rs @@ -262,9 +262,6 @@ impl<'de, 'a> MapAccess<'de> for SimpleMap<'a> { #[cfg(test)] mod tests { - // use std::collections::{HashMap, HashSet}; - // use std::fmt::Debug; - use std::collections::{HashMap, HashSet}; use std::fmt::Debug;