Skip to main content

nurtex_protocol/types/
chunk_data.rs

1use nurtex_codec::Buffer;
2use nurtex_codec::read_bytes;
3use nurtex_codec::types::variable::VarI32;
4
5use super::HeightmapsRaw;
6
7#[derive(Clone, Debug, PartialEq)]
8pub struct ChunkData {
9  /// Карты высот
10  pub heightmaps: HeightmapsRaw,
11
12  /// Сырые данные секций
13  pub sections: Vec<u8>,
14}
15
16impl Buffer for ChunkData {
17  fn read_buf(buffer: &mut std::io::Cursor<&[u8]>) -> Option<Self> {
18    Some(Self {
19      heightmaps: HeightmapsRaw::read_buf(buffer)?,
20      sections: {
21        let length = i32::read_var(buffer)? as usize;
22        read_bytes(buffer, length)?.to_vec()
23      },
24    })
25  }
26
27  fn write_buf(&self, buffer: &mut impl std::io::Write) -> std::io::Result<()> {
28    self.heightmaps.write_buf(buffer)?;
29    (self.sections.len() as i32).write_var(buffer)?;
30
31    Ok(())
32  }
33}