Got code to compile and serialize correctly
This commit is contained in:
parent
496a67cc7f
commit
63ff6e7c2c
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -1111,6 +1111,15 @@ dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_arrays"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38636132857f68ec3d5f3eb121166d2af33cb55174c4d5ff645db6165cbef0fd"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.189"
|
||||
@ -1191,6 +1200,7 @@ dependencies = [
|
||||
"parquet",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_arrays",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
]
|
||||
|
@ -12,5 +12,6 @@ clap = { version = "4.4.5", features = ["derive"] }
|
||||
parquet = "47.0.0"
|
||||
rand = "0.8.5"
|
||||
serde = { version = "1.0.189", features = ["derive"] }
|
||||
serde_arrays = "0.1.0"
|
||||
serde_json = "1.0.107"
|
||||
tokio = { version = "1.32.0", features = ["macros", "rt-multi-thread"] }
|
||||
|
@ -61,6 +61,7 @@ impl ChunkStorageCache {
|
||||
|
||||
&self.cached_chunk_files[last_used_index]
|
||||
}
|
||||
|
||||
/// `fetch_chunk_by_pos` takes in the position of a chunk, and returns the
|
||||
/// data of the chunk from disk
|
||||
///
|
||||
|
@ -1,5 +1,6 @@
|
||||
use core::fmt;
|
||||
use serde::ser;
|
||||
use serde::ser::{SerializeSeq, SerializeStruct, Serializer};
|
||||
use serde::Serialize;
|
||||
use std::{
|
||||
cmp::{max, min},
|
||||
@ -31,12 +32,26 @@ impl ChunkPos {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[derive(Debug)]
|
||||
pub struct ChunkData {
|
||||
pub pos: ChunkPos,
|
||||
pub sections: [ChunkSection; SECTIONS_PER_CHUNK],
|
||||
}
|
||||
|
||||
impl Serialize for ChunkData {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
let mut seq = serializer.serialize_seq(Some(self.sections.len()))?;
|
||||
|
||||
for section in self.sections {
|
||||
seq.serialize_element(§ion)?;
|
||||
}
|
||||
seq.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl ChunkData {
|
||||
pub fn new(pos: &ChunkPos) -> Self {
|
||||
ChunkData {
|
||||
@ -59,7 +74,7 @@ impl ChunkData {
|
||||
}
|
||||
|
||||
// https://wiki.vg/Chunk_Format
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, Serialize)]
|
||||
pub struct ChunkSection {
|
||||
/// The number of non-empty blocks in the section. If completely full, the
|
||||
/// section contains a 16 x 16 x 16 cube of blocks = 4096 blocks
|
||||
@ -68,6 +83,7 @@ pub struct ChunkSection {
|
||||
/// The data for all the blocks in the chunk
|
||||
/// The representation for this may be different based on the number of
|
||||
/// non-empty blocks
|
||||
#[serde(with = "serde_arrays")]
|
||||
block_states: [BlockID; 16 * 16 * 16],
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user