lize

Crates.iolize
lib.rslize
version0.1.1
created_at2025-01-28 16:02:10.813652+00
updated_at2025-03-01 12:08:47.287602+00
descriptionA stupid way of serializing and deserializing really small data into bytes. Supports recursive data structures.
homepage
repositoryhttps://github.com/AWeirdDev/lize
max_upload_size
id1533680
size23,134
JC (AWeirdDev)

documentation

README

lize

A stupid way of serializing data into a slice. Designed for really small data.

use lize::Value;

// You can create hashmaps like so:
let value = Value::HashMap(vec![
    (Value::Slice(b"hello"), Value::Slice(b"world")),
    (Value::Slice(b"money"), Value::I64(6969694200)),
]);

// ..then serialize it into a SmallVec (recommended)
let mut buffer = lize::SmallVec::<[u8; lize::STACK_N]>::new();
value.serialize_into(&mut buffer)?;

// Alternatively, you can serialize it into a Vec.
// That'd be more convenient.
// let buffer = value.serialize()?;

// Then, we can take a look at our deserialized data.
let deserialized = Value::deserialize_from(&buffer)?;
println!("{deserialized:?}");

let mut buffer = SmallVec::<[u8; lize::STACK_N]>::new();
value.serialize_into(&mut buffer)?;

Value

There are some other cool usages other than just hashmaps.

let value = Value::Vector(vec![
    Value::Bool(true),
    Value::Slice(b"hello"),

    Value::F64(std::f64::consts::PI),
    Value::I64(1234567890123456789),
    Value::I32(123456789),

    Value::Optional(Some(Box::new(Value::Slice(b"world")))),
    Value::Optional(None),

    Value::U8(1_u8),
    Value::SmallU8(123_u8) // Must be <= 235. Occupies a single byte.
]);

Of course, if you would, you can use Value::from(...) instead of doing that manually. Saves time!

let a = 123_i64;
let v = Value::from(a);

assert!(matches!(v, Value::I64(_)));

(de)serializing directly

You can use serialize(...) and deserialize(...) to have the Bincode-like interface.

let a = 123_i64;
let ser = serialize(a)?;

let b: i64 = deserialize(&ser)?;

assert_eq!(a, b);

(c) 2025 AWeirdDev

Commit count: 8

cargo fmt