use sim_codec::DecodeLimits as SharedDecodeLimits;
use sim_kernel::Symbol;
pub(crate) const VERSION: u128 = 1;
pub(crate) const FLAG_NONE: u128 = 0;
pub(crate) const FLAG_ORIGIN: u128 = 1;
pub(crate) const FLAG_TREE_ORIGIN: u128 = 2;
pub(crate) const FLAG_DENSE: u128 = 4;
pub(crate) const FLAG_KNOWN: u128 = FLAG_ORIGIN | FLAG_TREE_ORIGIN | FLAG_DENSE;
#[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 BitwiseFrame(
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(crate) enum BitwiseTag {
UInt0 = 0,
UInt1 = 1,
UInt2 = 2,
UInt3 = 3,
UInt4 = 4,
UInt5 = 5,
UInt6 = 6,
UInt7 = 7,
UInt8 = 8,
UInt9 = 9,
UInt10 = 10,
UInt11 = 11,
UInt12 = 12,
UInt13 = 13,
UInt14 = 14,
UInt15 = 15,
Nil = 16,
False = 17,
True = 18,
Number = 19,
Symbol = 20,
Local = 21,
String = 22,
Bytes = 23,
List = 24,
Vector = 25,
Map = 26,
Set = 27,
Call = 28,
Infix = 29,
Prefix = 30,
Postfix = 31,
Block = 32,
Quote = 33,
Annotated = 34,
Extension = 35,
Ref = 36,
}
impl BitwiseTag {
pub(crate) const WIDTH_BITS: usize = 6;
pub(crate) fn from_u6(value: u8) -> Option<Self> {
let tag = match value {
0 => Self::UInt0,
1 => Self::UInt1,
2 => Self::UInt2,
3 => Self::UInt3,
4 => Self::UInt4,
5 => Self::UInt5,
6 => Self::UInt6,
7 => Self::UInt7,
8 => Self::UInt8,
9 => Self::UInt9,
10 => Self::UInt10,
11 => Self::UInt11,
12 => Self::UInt12,
13 => Self::UInt13,
14 => Self::UInt14,
15 => Self::UInt15,
16 => Self::Nil,
17 => Self::False,
18 => Self::True,
19 => Self::Number,
20 => Self::Symbol,
21 => Self::Local,
22 => Self::String,
23 => Self::Bytes,
24 => Self::List,
25 => Self::Vector,
26 => Self::Map,
27 => Self::Set,
28 => Self::Call,
29 => Self::Infix,
30 => Self::Prefix,
31 => Self::Postfix,
32 => Self::Block,
33 => Self::Quote,
34 => Self::Annotated,
35 => Self::Extension,
36 => Self::Ref,
_ => return None,
};
Some(tag)
}
pub(crate) fn small_uint(self) -> Option<u8> {
let value = self as u8;
(value < 16).then_some(value)
}
}