Expand description
Cross-language serialization protocol for SciRS2.
Provides a versioned binary format (.scirs2 files) that can be
read by Python bindings, WASM modules, and native Rust code.
§Format
Header: 64 bytes, little-endian
- Magic:
b"SCIRS2\0\0"(8 bytes) - Version: u16 major, u16 minor (4 bytes)
- Payload type: u8 (1 byte): 0=array, 1=model, 2=stats, 3=custom
- Compression: u8 (1 byte): 0=none, 1=lz4, 2=zstd
- Checksum: u32 CRC32 of uncompressed payload (4 bytes)
- Payload length: u64 (8 bytes) — bytes actually stored on disk
- Reserved: 38 bytes of zeros
Payload (variable length, may be compressed):
- For arrays:
dtype(u8)+ndim(u8)+shape(u64 each, little-endian)+ raw element bytes (little-endian) - For models: JSON config + raw parameter bytes
- For stats: key-value pairs with typed values
- For custom: raw bytes (caller-defined format)
§Example
use scirs2_core::serialization::{save_array, load_array, CompressionType};
use ndarray::Array2;
use std::path::Path;
let data = Array2::<f32>::ones((3, 4)).into_dyn();
let path = Path::new("/tmp/test.scirs2");
save_array(path, &data, CompressionType::None).expect("should succeed");
let loaded = load_array::<f32>(path).expect("should succeed");
assert_eq!(data, loaded);Structs§
- Scirs2
Header - Parsed
.scirs2file header (64 bytes). - Scirs2
Reader - Low-level reader for
.scirs2files. - Scirs2
Writer - Low-level writer for
.scirs2files.
Enums§
- Compression
Type - Compression algorithm applied to the payload bytes.
- Payload
Type - Identifies the kind of data stored in the
.scirs2payload. - Serialization
Error - Errors that can occur during
.scirs2serialization or deserialization.
Traits§
- Array
Element - Element type supported by the
.scirs2array payload.
Functions§
- load_
array - Load an n-dimensional array from a
.scirs2file. - save_
array - Save an n-dimensional array to a
.scirs2file.