docs
This commit is contained in:
parent
befd894d89
commit
ed9e5da648
43
README.md
43
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<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`.
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user