array-object

Crates.ioarray-object
lib.rsarray-object
version0.3.0
created_at2024-10-13 19:59:43.874578+00
updated_at2026-01-16 14:41:22.02079+00
descriptionSelf-describing binary format for arrays of integers, floating-point numbers, complex numbers, and strings. It is designed for object storage, database integration, and single-file usage.
homepage
repositoryhttps://github.com/YShoji-HEP/ArrayObject
max_upload_size
id1407645
size139,840
Yutaro Shoji (YShoji-HEP)

documentation

README

Array Object

"Buy Me A Coffee" "GitHub Sponsors" Crates.io Crates.io License

ArrayObject is a self-describing binary format for arrays of integers, floating-point numbers, complex numbers, and strings. It is designed for efficient object storage, database integration, and single-file use.

ArrayObject is part of the dbgbb project.

Features

  • Self-describing data that can inflate into typed variables.
  • Simple, uniform arrays: no nested structures, tuples, or dataset names.
  • Generic integer and float types abstract away type size differences.
  • Automatic compression via variable-length encoding and dictionary coding for strings, minimizing storage size.
  • Seamless conversions to and from Vec<_>, [T; N], ndarray, and nalgebra.

Usage Examples

Encoding and Decoding

use array_object::*;

fn main() {
    // Convert data into binary
    let original = vec![1u32, 2, 3, 4];
    let obj: ArrayObject = original.clone().try_into().unwrap();
    let packed = obj.pack(); // Converts data into Vec<u8>

    // Restore data
    let unpacked = ArrayObject::unpack(packed).unwrap();
    let inflated: Vec<u32> = unpacked.try_into().unwrap();
    assert_eq!(original, inflated);
}

File Operations with Macros

use array_object::*;

fn main() {
    // Save to a file
    let original = vec![1f64, 2.2, -1.1, 5.6];
    export_obj!("testdata.bin", original.clone()); // Overwrites if file exists

    // Load from a file
    let restored: Vec<f64> = import_obj!("testdata.bin"); // Type annotation required
    assert_eq!(original, restored);
}

Crate Features

Feature Description
allow_float_down_convert Enables implicit conversion (e.g., f64 to f32).
ndarray_15 Enables ndarray support for version 0.15.x.
ndarray_16 Enables ndarray support for version 0.16.x.
ndarray_17 Enables ndarray support for version 0.16.x.
nalgebra_33 Enables nalgebra support for version 0.33.x.
nalgebra_34 Enables nalgebra support for version 0.34.x.
Commit count: 12

cargo fmt