Expand description
Custom binary serialisation format for scientific data.
This module provides three layers of binary I/O:
-
BinaryWriter/BinaryReader— low-level type-safe primitives (all integers, both float sizes, byte slices, length-prefixed strings, and prefixedf64arrays). All multi-byte values are stored in little-endian byte order for maximum portability. -
ScirsDataFile— a structured scientific container format built on top of the primitives:- Fixed 8-byte magic header (
SCIRS2DF) u8version numberu32record count- Sequence of named, typed
DataRecordentries
- Fixed 8-byte magic header (
-
DataRecord— the payload variant that a record may hold:Scalar,Vector,Matrix, andText.
§File layout
┌─────────────────────────────────────────────────────────┐
│ Magic : [u8; 8] = b"SCIRS2DF" │
│ Version : u8 = 1 │
│ N records: u32 LE │
├─────────────────────────────────────────────────────────┤
│ Record₁ │
│ Name : u32 LE length-prefix + UTF-8 bytes │
│ Tag : u8 (0=Scalar, 1=Vector, 2=Matrix, 3=Text) │
│ Data : │
│ Scalar → f64 LE │
│ Vector → u64 LE count + count×f64 LE │
│ Matrix → u64 rows + u64 cols + rows×cols×f64 LE │
│ Text → u32 LE length + UTF-8 bytes │
├─────────────────────────────────────────────────────────┤
│ Record₂ … │
└─────────────────────────────────────────────────────────┘§Examples
use scirs2_io::binary_format::{write_scirs, read_scirs, DataRecord};
let records = vec![
DataRecord::named("pi", DataRecord::Scalar(std::f64::consts::PI)),
DataRecord::named("data", DataRecord::Vector(vec![1.0, 2.0, 3.0])),
];
// write_scirs / read_scirs take &[(name, DataRecord)] and return Vec<(name, DataRecord)>
write_scirs("out.scirs2", &records).unwrap();
let loaded = read_scirs("out.scirs2").unwrap();Structs§
- Binary
Reader - Type-safe binary reader backed by a
BufReader<File>. - Binary
Writer - Type-safe binary writer backed by a
BufWriter<File>. - Scirs
Data File - Structured scientific data file (
SCIRS2DFformat).
Enums§
- Data
Record - The payload carried by a single named record in a
ScirsDataFile.
Functions§
- read_
scirs - Read all named
DataRecords from aSCIRS2DFbinary file. - write_
scirs - Write a sequence of named
DataRecords to aSCIRS2DFbinary file.