Skip to main content

haystack_core/codecs/trio/
mod.rs

1// Trio wire format codec — record-per-entity text format used for
2// definition files and entity data.
3
4mod encoder;
5mod parser;
6
7pub use encoder::encode_grid;
8pub use parser::decode_grid;
9
10use super::{Codec, CodecError};
11use crate::data::HGrid;
12use crate::kinds::Kind;
13
14/// Trio wire format codec.
15pub struct TrioCodec;
16
17impl Codec for TrioCodec {
18    fn mime_type(&self) -> &str {
19        "text/trio"
20    }
21
22    fn encode_grid(&self, grid: &HGrid) -> Result<String, CodecError> {
23        encode_grid(grid)
24    }
25
26    fn decode_grid(&self, input: &str) -> Result<HGrid, CodecError> {
27        decode_grid(input)
28    }
29
30    fn encode_scalar(&self, val: &Kind) -> Result<String, CodecError> {
31        // Trio delegates scalar encoding to Zinc
32        super::zinc::encode_scalar(val)
33    }
34
35    fn decode_scalar(&self, input: &str) -> Result<Kind, CodecError> {
36        // Trio delegates scalar decoding to Zinc
37        super::zinc::decode_scalar(input)
38    }
39}