Skip to main content

Crate tpt_uir_serde

Crate tpt_uir_serde 

Source
Expand description

§tpt-uir-serde

CI License: MIT OR Apache-2.0

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_op for single operations
  • serialize_region / deserialize_region for whole regions
  • write_tptuir / read_tptuir for .tptuir files (requires the std feature)

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(&region).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.