Crate torg_serde

Crate torg_serde 

Source
Expand description

Serialization/deserialization for TØR-G graphs.

This crate provides encoding and decoding of TØR-G graphs to various formats:

  • Binary: Compact format (~7 bytes per node) for storage and transmission
  • JSON: Human-readable format for debugging and inspection

§Binary Format

The binary format is designed for compactness and fast parsing:

Header:     [0x54, 0x47] "TG" magic + version:u8 + flags:u8
Inputs:     count:u16 + [id:u16; count]
Nodes:      count:u16 + [Node; count]
Outputs:    count:u16 + [id:u16; count]

§Examples

use torg_core::{Graph, Node, BoolOp, Source};
use torg_serde::{to_bytes, from_bytes, to_json, from_json};

// Create a simple graph
let graph = Graph {
    inputs: vec![0, 1],
    nodes: vec![Node::new(2, BoolOp::Or, Source::Id(0), Source::Id(1))],
    outputs: vec![2],
};

// Binary serialization
let bytes = to_bytes(&graph);
let restored = from_bytes(&bytes).unwrap();
assert_eq!(graph, restored);

// JSON serialization
let json = to_json(&graph);
let restored = from_json(&json).unwrap();
assert_eq!(graph, restored);

Re-exports§

pub use torg_core;

Enums§

SerdeError
Errors that can occur during serialization/deserialization.

Functions§

from_bytes
Deserialize a graph from binary format.
from_json
Deserialize a graph from JSON.
to_bytes
Serialize a graph to compact binary format.
to_json
Serialize a graph to pretty-printed JSON.
to_json_compact
Serialize a graph to compact JSON (no whitespace).