2023-11-25 03:07:09 +03:00
# bipack_ru: Rust Bipack implementation
2023-10-07 12:27:16 +03:00
2023-11-25 03:07:09 +03:00
Bipack serialization format is a compact binary format that was created as areplacement for a
BOSS format, mode compact, faster, and not revealing inner data structure as much as possible.
It is used in our next generation data protection systems, in DiWAN products as a base format and also in my newe communication package like [kiloparsec ](https://gitea.sergeych.net/sergeych/kiloparsec )
2023-11-25 02:45:35 +03:00
(and in underlying [crypto2 ](https://gitea.sergeych.net/sergeych/crypto2 )) which are intended
to replace older `Parsec` protocols family to cope with modern crazy world challenges.
>__IMPORTANT__ due to growing tensions in the world, the main development is moved to our [Gitea repository ](https://gitea.sergeych.net/DiWAN/bipack_ru ). We will try our best to make it available all around the world.
2023-10-12 02:49:10 +03:00
The most recent code will be there, and we encourage to use it also for issues/discussions.
2023-11-25 03:01:02 +03:00
> Beta test
2023-10-12 02:40:15 +03:00
2023-11-25 03:04:21 +03:00
# Use with serde:
2023-10-12 02:40:15 +03:00
2023-11-25 03:01:02 +03:00
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));
let restored: HashSet< String > = 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` .
2023-10-12 02:40:15 +03:00
2023-11-25 03:01:02 +03:00
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,
}
```
2023-11-25 03:04:21 +03:00
# Direct usage (no serde)
2023-10-12 02:40:15 +03:00
The sample code (see `src/lib.rs` for more:)
```rust
fn test() {
let mut data = Vec::< u8 > ::new();
data.put_str("Hello, rupack!");
println!("size ${}\n{}", data.len(), to_dump(&data));
let mut src = SliceSource::from(&data);
assert_eq!("Hello, rupack!", src.get_str().unwrap());
}
```
## Tools and macros
- `to_dump` to convert binary slice into human-readable dump
2023-10-12 02:53:12 +03:00
- `StringBuilder` super minimalistic string builder (footprint).
2023-10-12 00:18:46 +03:00
2023-10-10 09:02:36 +03:00
The autodoc documentation is good enough already, so we do not repeat it here now.
2023-10-12 02:40:15 +03:00
## How to
- just ad this package to your dependencies, it is on crates.io.
2023-11-25 02:37:48 +03:00
## Big thanks
- to https://github.com/jamesmunns for the brilliant postcard format which was used as a model.
2023-10-10 09:02:36 +03:00
# License
2023-10-12 00:18:46 +03:00
For compliance with other modules this work is provided under APACHE 2.0 license a copy of which is included in the file `LICENSE` .