This commit is contained in:
Sergey Chernov 2023-11-25 03:01:02 +03:00
parent befd894d89
commit ed9e5da648
2 changed files with 32 additions and 14 deletions

View File

@ -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. 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 let restored: HashSet<String> = from_bytes(&packed)?;
- i8, i16, i32, i64, `smartint` variable-length signed println!("{:?}", restored);
- strings (utf8, variable length) assert_eq!(src, restored);
- fixed size byte arrays }
- variable length byte arrays ```
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:) The sample code (see `src/lib.rs` for more:)
```rust ```rust
@ -39,9 +63,6 @@ fn test() {
- `StringBuilder` super minimalistic string builder (footprint). - `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. The autodoc documentation is good enough already, so we do not repeat it here now.
## How to ## How to

View File

@ -262,9 +262,6 @@ impl<'de, 'a> MapAccess<'de> for SimpleMap<'a> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
// use std::collections::{HashMap, HashSet};
// use std::fmt::Debug;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::fmt::Debug; use std::fmt::Debug;