diff options
| author | mat <github@matdoes.dev> | 2022-04-26 15:33:41 +0000 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-04-26 15:33:41 +0000 |
| commit | e5fcfa119309877ab515b921f8ada5f1b1ec4c30 (patch) | |
| tree | c5084a2f7840979feaf7483e7b598cbc888c509f /azalea-protocol/src/mc_buf/write.rs | |
| parent | f9528a9f9a9e73b1d657af7c78d743067307d843 (diff) | |
| download | azalea-drasl-e5fcfa119309877ab515b921f8ada5f1b1ec4c30.tar.xz | |
default implementation for read and write Vec<T>
Diffstat (limited to 'azalea-protocol/src/mc_buf/write.rs')
| -rwxr-xr-x | azalea-protocol/src/mc_buf/write.rs | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/azalea-protocol/src/mc_buf/write.rs b/azalea-protocol/src/mc_buf/write.rs index f1362402..e8845f25 100755 --- a/azalea-protocol/src/mc_buf/write.rs +++ b/azalea-protocol/src/mc_buf/write.rs @@ -1,5 +1,4 @@ -use super::MAX_STRING_LENGTH; -use crate::mc_buf::ByteArray; +use super::{UnsizedByteArray, MAX_STRING_LENGTH}; use async_trait::async_trait; use azalea_chat::component::Component; use azalea_core::{ @@ -187,15 +186,17 @@ impl McBufVarintWritable for i32 { } } -impl McBufWritable for Vec<u8> { +impl McBufWritable for UnsizedByteArray { fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> { buf.write_bytes(self) } } -impl McBufWritable for ByteArray { +// TODO: use specialization when that gets stabilized into rust +// to optimize for Vec<u8> byte arrays +impl<T: McBufWritable> McBufWritable for Vec<T> { fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> { - buf.write_byte_array(&self) + buf.write_list(self, |buf, i| T::write_into(i, buf)) } } @@ -304,15 +305,6 @@ impl McBufWritable for Option<GameType> { } } -// Vec<ResourceLocation> -impl McBufWritable for Vec<ResourceLocation> { - fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> { - buf.write_list(self, |buf, resource_location| { - buf.write_resource_location(resource_location) - }) - } -} - // azalea_nbt::Tag impl McBufWritable for azalea_nbt::Tag { fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> { |
