aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-03-28 01:15:09 +0200
committernea <nea@nea.moe>2023-03-28 01:15:09 +0200
commit2277cf2705760e9c2f50a972b89fd567daf263bb (patch)
tree7d17ada832187ffea3fee42c5199d186d8ae3e3e /src
parente1cd9eac3c223c39a7d3e0ead916037585d25c35 (diff)
downloadmcproto-rs-1.19.3.tar.gz
mcproto-rs-1.19.3.tar.bz2
mcproto-rs-1.19.3.zip
Better blob storageHEAD1.19.3
Diffstat (limited to 'src')
-rw-r--r--src/v1_19_3.rs47
1 files changed, 37 insertions, 10 deletions
diff --git a/src/v1_19_3.rs b/src/v1_19_3.rs
index 5495c3d..131f02e 100644
--- a/src/v1_19_3.rs
+++ b/src/v1_19_3.rs
@@ -319,18 +319,28 @@ proto_struct!(ChunkSection {
biomes: PalettedContainer,
});
+
+
#[derive(Debug, Clone, PartialEq)]
-pub struct PalettedContainer {
- // TODO: global, linear and hashed palettes
- pub singular_value: VarInt,
+pub enum PalettedContainer {
+ SingularValue(VarInt),
+ GlobalPalette(BlobArray),
}
impl Serialize for PalettedContainer {
fn mc_serialize<S: Serializer>(&self, to: &mut S) -> SerializeResult {
- to.serialize_byte(0)?;
- to.serialize_other(&self.singular_value)?;
- // Serialize 0 bit bitstorage
- to.serialize_other(&BitSet::empty())?;
+ match self {
+ PalettedContainer::SingularValue(value) => {
+ to.serialize_byte(0)?;
+ to.serialize_other(value)?;
+ // Serialize 0 bit bitstorage
+ to.serialize_other(&BitSet::empty())?;
+ }
+ PalettedContainer::GlobalPalette(data) => {
+ to.serialize_byte(9)?;
+ to.serialize_other(data)?;
+ }
+ }
Ok(())
}
}
@@ -341,7 +351,7 @@ impl Deserialize for PalettedContainer {
}
}
-
+#[derive(Debug, PartialEq, Clone)]
pub struct BlobArray {
// TODO make this work same as bit storage with a const generic entry size
pub data: Vec<u64>,
@@ -365,7 +375,7 @@ impl BlobArray {
let entries_per_long = 64usize / self.entry_size;
let array_index = index / entries_per_long;
let position = index % entries_per_long;
- let array_shift = 64 - (entries_per_long - position) * self.entry_size;
+ let array_shift = position * self.entry_size;
let mask = (1u64 << self.entry_size) - 1;
self.ensure_capacity(index);
self.data[array_index] |= (value & mask) << array_shift;
@@ -375,13 +385,30 @@ impl BlobArray {
let entries_per_long = 64 / self.entry_size;
let array_index = index / entries_per_long;
let position = index % entries_per_long;
- let array_shift = 64 - (entries_per_long - position) * self.entry_size;
+ let array_shift = position * self.entry_size;
let mask = (1u64 << self.entry_size) - 1;
self.ensure_capacity(index);
(self.data[array_index] >> array_shift) & mask
}
}
+impl Serialize for BlobArray {
+ fn mc_serialize<S: Serializer>(&self, to: &mut S) -> SerializeResult {
+ to.serialize_other(&VarInt::from(self.data.len() as i32))?;
+ for elem in &self.data {
+ to.serialize_other(elem)?;
+ }
+ Ok(())
+ }
+}
+
+impl Deserialize for BlobArray {
+ fn mc_deserialize(_data: &[u8]) -> DeserializeResult<Self> {
+ Err(DeserializeErr::CannotUnderstandValue("Not implemented".into()))
+ }
+}
+
+
proto_struct!(BitSet {
data: CountedArray<u64, VarInt>,
});