chive 0.1.0

A low-level type-safe binary serialization library with support for numbers, arrays, strings, and nested sub-archives
Documentation
  • Coverage
  • 88%
    88 out of 100 items documented0 out of 84 items with examples
  • Size
  • Source code size: 38.49 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 870.21 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • timstr/chive
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • timstr

chive

A low-level binary format serialization and deserialization library with support for integer and floating point values and arrays of values, UTF-8 strings, and nested sub-archives.

let chive = Chive::with_chive_in(|mut chive_in| {
    chive_in.u8(1);
    chive_in.u16(2);
    chive_in.array_slice_u8(&[0, 1, 2, 3]);
    chive_in.array_slice_u64(&[10, 11, 12, 13]);
    chive_in.string("Testing");

    chive_in.nest(|mut nested_chive_in| {
        nested_chive_in.u8(3);
        nested_chive_in.u16(4);
        nested_chive_in.array_slice_u8(&[20, 21, 22, 23]);
        nested_chive_in.array_slice_u64(&[30, 31, 32, 33]);
    });

    chive_in.u8(1);
});

let raw_data = chive.into_vec();
// use raw_data to save to file, send over network, encode as Base64, whatever

Individual values are stored as a type tag followed by the binary value. For strings, arrays, and sub-archives, the length is also encoded between the type tag and the value. During deserialization, the type and length can be inspected without reading or consuming the following value to make runtime decisions about how to interpret the archive. Otherwise, during deserialization, strongly-typed values can be read eagerly and easily using the Result<>-based interface.

let chive = Chive::load_from_file("path/to/file.dat")?;
let chive_out = chive.chive_out()?;
let id = d.u16()?;
let values = chive_out.array_slice_u16()?;
let name = chive_out.string()?;
{
    let nested_chive_out = chive_out.nest()?;
    let inner_values = nested_chive_out.array_slice_f32()?;
}

Arrays can be serialized and deserialized using iterators as well as slices and Vec.

for i in chive_out.array_iter_u16()? {
    println!("{}", i);
}

chive_out.array_iter_u16(some_hash_map.keys().cloned());

Features not included

  • Versioning
  • Named fields
  • JSON / BSON / serde compatibility
  • Compression