Expand description
§tpt-uir-serde
Compact binary (de)serialization for the TPT Unified Intermediate Representation (TPT-UIR) using postcard.
Postcard produces a small, self-describing wire format suitable for storage and
transport. It is not zero-copy: decoding allocates and deserializes into owned
Operation/Region values. For a true zero-copy, memory-mapped format, see the
tpt-uir-flatbuffers crate.
This crate builds on tpt-uir-core (with its serde
feature enabled) and provides:
serialize_op/deserialize_opfor single operationsserialize_region/deserialize_regionfor whole regionswrite_tptuir/read_tptuirfor.tptuirfiles (requires thestdfeature)
It is no_std by default; enable the std feature for file I/O helpers.
§Installation
Not yet on crates.io — depend on it via git or a path within this workspace:
[dependencies]
tpt-uir-serde = { git = "https://github.com/tpt-solutions/tpt-uir", package = "tpt-uir-serde", features = ["std"] }§Example
use tpt_uir_serde::{serialize_region, deserialize_region};
use tpt_uir_core::{Region, Block, Operation, OpName, Type};
let region = Region {
blocks: vec![Block {
arguments: vec![(0u32, Type::Index)],
operations: vec![Operation {
id: 1,
op_name: OpName::parse("core.add").unwrap(),
operands: vec![0],
results: vec![1],
regions: vec![],
attributes: vec![],
}],
}],
};
let bytes = serialize_region(®ion).unwrap();
let back = deserialize_region(&bytes).unwrap();
assert_eq!(region, back);See CHANGELOG.md for release notes.
§License
Licensed under either of MIT or Apache-2.0 at your option.
Functions§
- deserialize_
op - Deserialize a single operation from postcard bytes.
- deserialize_
region - Deserialize a region from postcard bytes.
- serialize_
op - Serialize a single operation to a postcard byte vector.
- serialize_
region - Serialize a region to a postcard byte vector.