aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/mc_buf
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-protocol/src/mc_buf')
-rw-r--r--azalea-protocol/src/mc_buf/read.rs66
-rw-r--r--azalea-protocol/src/mc_buf/write.rs42
2 files changed, 108 insertions, 0 deletions
diff --git a/azalea-protocol/src/mc_buf/read.rs b/azalea-protocol/src/mc_buf/read.rs
index 683c7d9a..374e5443 100644
--- a/azalea-protocol/src/mc_buf/read.rs
+++ b/azalea-protocol/src/mc_buf/read.rs
@@ -238,3 +238,69 @@ impl McBufReadable for Vec<u8> {
buf.read_bytes().await
}
}
+
+// string
+#[async_trait]
+impl McBufReadable for String {
+ async fn read_into<R>(buf: &mut R) -> Result<Self, String>
+ where
+ R: AsyncRead + std::marker::Unpin + std::marker::Send,
+ {
+ buf.read_utf().await
+ }
+}
+
+// ResourceLocation
+#[async_trait]
+impl McBufReadable for ResourceLocation {
+ async fn read_into<R>(buf: &mut R) -> Result<Self, String>
+ where
+ R: AsyncRead + std::marker::Unpin + std::marker::Send,
+ {
+ buf.read_resource_location().await
+ }
+}
+
+// u32
+#[async_trait]
+impl McBufReadable for u32 {
+ async fn read_into<R>(buf: &mut R) -> Result<Self, String>
+ where
+ R: AsyncRead + std::marker::Unpin + std::marker::Send,
+ {
+ buf.read_int().await.map(|i| i as u32)
+ }
+}
+
+// u32 varint
+#[async_trait]
+impl McBufVarintReadable for u32 {
+ async fn varint_read_into<R>(buf: &mut R) -> Result<Self, String>
+ where
+ R: AsyncRead + std::marker::Unpin + std::marker::Send,
+ {
+ buf.read_varint().await.map(|i| i as u32)
+ }
+}
+
+// u16
+#[async_trait]
+impl McBufReadable for u16 {
+ async fn read_into<R>(buf: &mut R) -> Result<Self, String>
+ where
+ R: AsyncRead + std::marker::Unpin + std::marker::Send,
+ {
+ buf.read_short().await.map(|i| i as u16)
+ }
+}
+
+// u16 varint
+#[async_trait]
+impl McBufVarintReadable for u16 {
+ async fn varint_read_into<R>(buf: &mut R) -> Result<Self, String>
+ where
+ R: AsyncRead + std::marker::Unpin + std::marker::Send,
+ {
+ buf.read_varint().await.map(|i| i as u16)
+ }
+}
diff --git a/azalea-protocol/src/mc_buf/write.rs b/azalea-protocol/src/mc_buf/write.rs
index 7b1ac861..f22b218a 100644
--- a/azalea-protocol/src/mc_buf/write.rs
+++ b/azalea-protocol/src/mc_buf/write.rs
@@ -184,3 +184,45 @@ impl McBufWritable for Vec<u8> {
buf.write_bytes(self)
}
}
+
+// string
+impl McBufWritable for String {
+ fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ buf.write_utf(self)
+ }
+}
+
+// ResourceLocation
+impl McBufWritable for ResourceLocation {
+ fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ buf.write_resource_location(self)
+ }
+}
+
+// u32
+impl McBufWritable for u32 {
+ fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ buf.write_varint(*self as i32)
+ }
+}
+
+// u32 varint
+impl McBufVarintWritable for u32 {
+ fn varint_write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ buf.write_varint(*self as i32)
+ }
+}
+
+// u16
+impl McBufWritable for u16 {
+ fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ buf.write_varint(*self as i32)
+ }
+}
+
+// u16 varint
+impl McBufVarintWritable for u16 {
+ fn varint_write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ buf.write_varint(*self as i32)
+ }
+}