#![doc = include_str!("../README.md")]
#![warn(missing_docs)]
pub use databuf_derive::*;
pub mod config;
pub mod error;
pub mod var_int;
mod record;
mod types;
mod utils;
use std::{io, io::Write};
pub type Error = Box<dyn std::error::Error + Send + Sync>;
pub type Result<T, E = Error> = std::result::Result<T, E>;
pub trait Encode {
fn encode<const CONFIG: u16>(&self, _: &mut (impl Write + ?Sized)) -> io::Result<()>;
#[inline]
fn to_bytes<const CONFIG: u16>(&self) -> Vec<u8> {
let mut vec = Vec::new();
self.encode::<CONFIG>(&mut vec).unwrap();
vec
}
}
pub trait Decode<'de>: Sized {
fn decode<const CONFIG: u16>(_: &mut &'de [u8]) -> Result<Self>;
#[inline]
fn from_bytes<const CONFIG: u16>(bytes: &'de [u8]) -> Result<Self> {
let mut reader = bytes;
Decode::decode::<CONFIG>(&mut reader)
}
}
pub trait DecodeOwned: for<'de> Decode<'de> {}
impl<T> DecodeOwned for T where T: for<'de> Decode<'de> {}