aboutsummaryrefslogtreecommitdiff
path: root/azalea-world/src/chunk_storage.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-10-07 20:12:36 -0500
committerGitHub <noreply@github.com>2022-10-07 20:12:36 -0500
commitbc3aa9467ae1e2d0ea1727093af9b0af14965e69 (patch)
tree8db3b735daed484507129eb0683db88ddec14210 /azalea-world/src/chunk_storage.rs
parent695efef66fdf1e08f0cb6d8783c085875100fa2d (diff)
downloadazalea-drasl-bc3aa9467ae1e2d0ea1727093af9b0af14965e69.tar.xz
Replace impl Read with Cursor<&[u8]> (#26)
* Start getting rid of Cursor * try to make the tests pass and fail * make the tests pass * remove unused uses * fix clippy warnings * fix potential OOM exploits * fix OOM in az-nbt * fix nbt benchmark * fix a test * start replacing it with Cursor<Vec<u8>> * wip * fix all the issues * fix all tests * fix nbt benchmark * fix warnings
Diffstat (limited to 'azalea-world/src/chunk_storage.rs')
-rw-r--r--azalea-world/src/chunk_storage.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/azalea-world/src/chunk_storage.rs b/azalea-world/src/chunk_storage.rs
index 9d81b28f..566b3198 100644
--- a/azalea-world/src/chunk_storage.rs
+++ b/azalea-world/src/chunk_storage.rs
@@ -7,8 +7,9 @@ use azalea_buf::{McBufReadable, McBufWritable};
use azalea_core::floor_mod;
use azalea_core::{BlockPos, ChunkBlockPos, ChunkPos, ChunkSectionBlockPos};
use std::fmt::Debug;
+use std::io::Cursor;
use std::{
- io::{Read, Write},
+ io::Write,
ops::{Index, IndexMut},
sync::{Arc, Mutex},
};
@@ -100,7 +101,7 @@ impl ChunkStorage {
pub fn replace_with_packet_data(
&mut self,
pos: &ChunkPos,
- data: &mut impl Read,
+ data: &mut Cursor<&[u8]>,
) -> Result<(), BufReadError> {
if !self.in_range(pos) {
println!(
@@ -137,14 +138,14 @@ impl IndexMut<&ChunkPos> for ChunkStorage {
impl Chunk {
pub fn read_with_dimension(
- buf: &mut impl Read,
+ buf: &mut Cursor<&[u8]>,
data: &Dimension,
) -> Result<Self, BufReadError> {
Self::read_with_dimension_height(buf, data.height())
}
pub fn read_with_dimension_height(
- buf: &mut impl Read,
+ buf: &mut Cursor<&[u8]>,
dimension_height: u32,
) -> Result<Self, BufReadError> {
let section_count = dimension_height / SECTION_HEIGHT;
@@ -216,7 +217,7 @@ impl Debug for ChunkStorage {
}
impl McBufReadable for Section {
- fn read_from(buf: &mut impl Read) -> Result<Self, BufReadError> {
+ fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
let block_count = u16::read_from(buf)?;
// this is commented out because the vanilla server is wrong