1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#[cfg(feature = "core")]
pub mod core;

#[cfg(feature = "std")]
pub mod std;

pub type TBuffer<'a> = dyn Iterator<Item = u8> + 'a;

pub trait TBytes {
    fn size(&self) -> usize;

    fn to_bytes(&self) -> Vec<u8>;

    fn from_bytes(buffer: &mut TBuffer) -> Option<Self>
    where
        Self: Sized;

    fn from_bytes_ref(buffer: &[u8]) -> Option<Self>
    where
        Self: Sized,
    {
        let mut buffer = buffer.to_vec();
        let tmp = Self::from_bytes(&mut buffer.drain(..));
        tmp
    }
}

pub extern crate bytes_kman_derive;
pub use bytes_kman_derive::Bytes;

pub mod prelude {
    pub use super::Bytes;
    pub use super::TBuffer;
    pub use super::TBytes;
}