use sim_codec::DecodeLimits as SharedDecodeLimits;
use sim_kernel::Symbol;
pub(crate) const MAGIC: &[u8; 4] = b"SLB8";
pub(crate) const VERSION: u64 = 1;
pub(crate) const FLAG_NONE: u64 = 0;
pub(crate) const FLAG_ORIGIN: u64 = 1;
pub(crate) const FLAG_TREE_ORIGIN: u64 = 2;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct DecodeLimits {
pub max_frame_bytes: usize,
pub max_string_bytes: usize,
pub max_blob_bytes: usize,
pub max_table_entries: usize,
pub max_expr_nodes: usize,
pub max_depth: usize,
pub max_trivia_items: usize,
}
impl Default for DecodeLimits {
fn default() -> Self {
SharedDecodeLimits::default().into()
}
}
impl From<SharedDecodeLimits> for DecodeLimits {
fn from(shared: SharedDecodeLimits) -> Self {
Self {
max_frame_bytes: shared.max_input_bytes,
max_string_bytes: shared.max_string_bytes,
max_blob_bytes: shared.max_blob_bytes,
max_table_entries: shared.max_collection_len,
max_expr_nodes: shared.max_expr_nodes,
max_depth: shared.max_depth,
max_trivia_items: shared.max_trivia_items,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct BinaryFrame(
pub Vec<u8>,
);
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FrameTables {
pub libs: Vec<String>,
pub symbols: Vec<Symbol>,
pub number_domains: Vec<Symbol>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum BinaryTag {
Nil = 0x00,
False = 0x01,
True = 0x02,
Number = 0x03,
Symbol = 0x04,
String = 0x05,
Bytes = 0x06,
List = 0x07,
Vector = 0x08,
Map = 0x09,
Set = 0x0a,
Call = 0x0b,
Infix = 0x0c,
Prefix = 0x0d,
Postfix = 0x0e,
Block = 0x0f,
Quote = 0x10,
Annotated = 0x11,
Extension = 0x12,
Local = 0x13,
}
impl BinaryTag {
pub(crate) fn from_byte(byte: u8) -> Option<Self> {
match byte {
0x00 => Some(Self::Nil),
0x01 => Some(Self::False),
0x02 => Some(Self::True),
0x03 => Some(Self::Number),
0x04 => Some(Self::Symbol),
0x05 => Some(Self::String),
0x06 => Some(Self::Bytes),
0x07 => Some(Self::List),
0x08 => Some(Self::Vector),
0x09 => Some(Self::Map),
0x0a => Some(Self::Set),
0x0b => Some(Self::Call),
0x0c => Some(Self::Infix),
0x0d => Some(Self::Prefix),
0x0e => Some(Self::Postfix),
0x0f => Some(Self::Block),
0x10 => Some(Self::Quote),
0x11 => Some(Self::Annotated),
0x12 => Some(Self::Extension),
0x13 => Some(Self::Local),
_ => None,
}
}
}