diff options
author | Joey Sacchini <joey@sacchini.net> | 2021-01-08 15:37:01 -0500 |
---|---|---|
committer | Joey Sacchini <joey@sacchini.net> | 2021-01-08 15:37:01 -0500 |
commit | b67603827b24272517b43a7249b0f63625308735 (patch) | |
tree | a255434aae355eb9bb7365424885d7cc47d69532 /src/reader.rs | |
parent | 298463659a38df8d1f17992851cb64c7309600a1 (diff) | |
download | craftio-rs-b67603827b24272517b43a7249b0f63625308735.tar.gz craftio-rs-b67603827b24272517b43a7249b0f63625308735.tar.bz2 craftio-rs-b67603827b24272517b43a7249b0f63625308735.zip |
add some functions to ensure buffer is allocated on a CraftIO implementor
Diffstat (limited to 'src/reader.rs')
-rw-r--r-- | src/reader.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/reader.rs b/src/reader.rs index bba028e..b3bb2dd 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -172,6 +172,26 @@ impl<R> CraftIo for CraftReader<R> { debug_assert!(max_size > 5); self.max_packet_size = max_size; } + + fn ensure_buf_capacity(&mut self, capacity: usize) { + let alloc_to = if capacity > self.max_packet_size { + self.max_packet_size + } else { + capacity + }; + self.move_ready_data_to_front(); + get_sized_buf(&mut self.raw_buf, 0, alloc_to); + } + + #[cfg(feature = "compression")] + fn ensure_compression_buf_capacity(&mut self, capacity: usize) { + let alloc_to = if capacity > self.max_packet_size { + self.max_packet_size + } else { + capacity + }; + get_sized_buf(&mut self.decompress_buf, 0, alloc_to); + } } macro_rules! rr_unwrap { |