From 966471f740ea7cb19e7106000a9f3cf9d306fd32 Mon Sep 17 00:00:00 2001 From: mat Date: Thu, 9 Dec 2021 22:10:45 +0000 Subject: split mstuff --- minecraft-protocol/src/mc_buf.rs | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'minecraft-protocol/src/mc_buf.rs') 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, 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( +pub async fn read_utf_with_len( buf: &mut BufReader, max_length: u32, ) -> Result { @@ -146,8 +134,24 @@ pub async fn read_utf( Ok(string) } +pub fn write_utf_with_len(buf: &mut Vec, 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(buf: &mut T) -> Result { + read_utf_with_len(buf, MAX_STRING_LENGTH.into()).await +} + pub fn write_utf(buf: &mut Vec, 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, n: u16) { -- cgit v1.2.3