aboutsummaryrefslogtreecommitdiff
path: root/minecraft-protocol/src/mc_buf.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2021-12-09 22:10:45 +0000
committermat <github@matdoes.dev>2021-12-09 22:10:45 +0000
commit966471f740ea7cb19e7106000a9f3cf9d306fd32 (patch)
tree7bec45bf72900ad6a1752ec9f7c172f385736880 /minecraft-protocol/src/mc_buf.rs
parentecee5e96ca2f7d00dd14f44ff0c1facd01550b65 (diff)
downloadazalea-drasl-966471f740ea7cb19e7106000a9f3cf9d306fd32.tar.xz
split mstuff
Diffstat (limited to 'minecraft-protocol/src/mc_buf.rs')
-rw-r--r--minecraft-protocol/src/mc_buf.rs32
1 files changed, 18 insertions, 14 deletions
diff --git a/minecraft-protocol/src/mc_buf.rs b/minecraft-protocol/src/mc_buf.rs
index a58905b7..087e66a1 100644
--- a/minecraft-protocol/src/mc_buf.rs
+++ b/minecraft-protocol/src/mc_buf.rs
@@ -96,19 +96,7 @@ mod tests {
}
}
-pub fn write_utf_with_len(buf: &mut Vec<u8>, string: &String, len: usize) {
- if string.len() > len {
- panic!(
- "String too big (was {} bytes encoded, max {})",
- string.len(),
- len
- );
- }
- write_varint(buf, string.len() as i32);
- write_bytes(buf, string.as_bytes());
-}
-
-pub async fn read_utf<T: AsyncRead + std::marker::Unpin>(
+pub async fn read_utf_with_len<T: AsyncRead + std::marker::Unpin>(
buf: &mut BufReader<T>,
max_length: u32,
) -> Result<String, String> {
@@ -146,8 +134,24 @@ pub async fn read_utf<T: AsyncRead + std::marker::Unpin>(
Ok(string)
}
+pub fn write_utf_with_len(buf: &mut Vec<u8>, string: &String, len: usize) {
+ if string.len() > len {
+ panic!(
+ "String too big (was {} bytes encoded, max {})",
+ string.len(),
+ len
+ );
+ }
+ write_varint(buf, string.len() as i32);
+ write_bytes(buf, string.as_bytes());
+}
+
+pub async fn read_utf<T: AsyncRead + std::marker::Unpin>(buf: &mut T) -> Result<String, String> {
+ read_utf_with_len(buf, MAX_STRING_LENGTH.into()).await
+}
+
pub fn write_utf(buf: &mut Vec<u8>, string: &String) {
- write_utf_with_len(buf, string, MAX_STRING_LENGTH as usize);
+ write_utf_with_len(buf, string, MAX_STRING_LENGTH.into());
}
pub fn write_short(buf: &mut Vec<u8>, n: u16) {