plotnik_core/grammar/
binary.rs

1//! Binary serialization for grammars using postcard.
2
3use super::json::GrammarError;
4use super::types::Grammar;
5
6impl Grammar {
7    /// Deserialize grammar from binary format.
8    pub fn from_binary(bytes: &[u8]) -> Result<Self, GrammarError> {
9        postcard::from_bytes(bytes).map_err(GrammarError::Binary)
10    }
11
12    /// Serialize grammar to binary format.
13    pub fn to_binary(&self) -> Vec<u8> {
14        postcard::to_allocvec(self).expect("serialization should not fail")
15    }
16}