1
0
Fork 0
mirror of https://github.com/azalea-rs/simdnbt.git synced 2025-08-02 07:26:04 +00:00

write structs and unions for tape

This commit is contained in:
mat 2024-05-18 05:03:08 +00:00
parent eb960e076e
commit 8b71281508
3 changed files with 99 additions and 0 deletions

3
.gitignore vendored
View file

@ -12,3 +12,6 @@ cachegrind.out.*
# sometimes i make these files when benchmarking, don't want to accidentally commit them
benchmark_result.txt
valgrind.txt
# thanks rust
rustc-ice*.txt

View file

@ -3,6 +3,7 @@
mod compound;
mod list;
mod tag_alloc;
mod tape;
use std::{io::Cursor, ops::Deref};

View file

@ -0,0 +1,95 @@
pub struct Tape {
pub elements: Vec<TapeElement>,
}
#[repr(C)]
pub union TapeElement {
kind: (TapeTagKind, TapeTagValue),
long: i64,
double: f64,
}
#[repr(C, packed)]
#[derive(Copy, Clone)]
pub union TapeTagValue {
byte: i8,
short: i16,
int: i32,
long: (), // value is in next tape element
float: f32,
double: (), // value is in next tape element
byte_array: u56, // pointer to the original data
string: u56, // pointer to the original data
compound: (u24, UnalignedU32), // length estimate + tape index to the end of the compound
int_array: u56, // pointer to the original data
long_array: u56, // pointer to the original data
// lists
empty_list: (),
byte_list: u56, // pointer to the original data
short_list: u56, // pointer to the original data
int_list: u56, // pointer to the original data
long_list: u56, // pointer to the original data
float_list: u56, // pointer to the original data
double_list: u56, // pointer to the original data
byte_array_list: u56, // pointer to a fat pointer we keep elsewhere that points to the original data
string_list: u56, // pointer to a fat pointer
list_list: (u24, UnalignedU32), // length estimate + tape index to the end of the list
compound_list: (u24, UnalignedU32), // length estimate + tape index to the end of the list
int_array_list: u56, // pointer to a fat pointer
long_array_list: u56, // pointer to a fat pointer
}
#[derive(Debug, Copy, Clone)]
#[repr(packed)]
pub struct u56 {
a: u8,
b: u16,
c: u32,
}
#[derive(Debug, Copy, Clone)]
#[repr(packed)]
pub struct u48 {
a: u16,
b: u32,
}
#[derive(Debug, Copy, Clone)]
#[repr(packed)]
pub struct u24 {
a: u8,
b: u16,
}
#[derive(Debug, Copy, Clone)]
#[repr(packed)]
pub struct UnalignedU32(pub u32);
#[derive(Clone, Copy)]
#[repr(u8)]
enum TapeTagKind {
Byte,
Short,
Int,
Long,
Float,
Double,
ByteArray,
String,
Compound,
IntArray,
LongArray,
EmptyList,
ByteList,
ShortList,
IntList,
LongList,
FloatList,
DoubleList,
ByteArrayList,
StringList,
ListList,
CompoundList,
IntArrayList,
LongArrayList,
}