binary_codec/
lib.rs

1#[derive(Debug)]
2pub enum SerializationError {
3    /// Value is out of bounds (value, min, max)
4    ValueOutOfBounds(i32, i32, i32),
5
6    // Unexpected size (expected, actual)
7    UnexpectedLength(usize, usize),
8
9    /// Missing runtime length key
10    MissingLengthByKey(String),
11
12    /// Validation did fail for the data
13    InvalidData(String),
14}
15
16#[derive(Debug)]
17pub enum DeserializationError {
18    /// Not enough bytes (bytes missing)
19    NotEnoughBytes(usize),
20
21    // Unexpected size (expected, actual)
22    UnexpectedLength(usize, usize),
23
24    /// Unknown enum discriminator
25    UnknownDiscriminant(u8),
26
27    /// Missing runtime length key
28    MissingLengthByKey(String),
29
30    /// Validation did fail for the data
31    InvalidData(String),
32}
33
34pub trait BinarySerializer {
35    fn to_bytes(&self, config: Option<&mut SerializerConfig>) -> Result<Vec<u8>, SerializationError>;
36    fn write_bytes(&self, buffer: &mut Vec<u8>, config: Option<&mut SerializerConfig>) -> Result<(), SerializationError>;
37}
38
39pub trait BinaryDeserializer : Sized {
40    fn from_bytes(bytes: &[u8], config: Option<&mut SerializerConfig>) -> Result<Self, DeserializationError>;
41}
42
43mod config;
44pub mod utils;
45pub mod dynamics;
46pub mod fixed_int;
47pub mod dyn_int;
48pub mod variable;
49
50pub use binary_codec_derive::{ToBytes, FromBytes};
51pub use config::SerializerConfig;