diff --git a/src/nbt/mod.rs b/src/nbt/mod.rs index e72fad6..37c3eca 100644 --- a/src/nbt/mod.rs +++ b/src/nbt/mod.rs @@ -304,7 +304,8 @@ pub fn write_string(buf: &mut W, s: &str) -> Result<(), protocol:: pub fn read_string(buf: &mut R) -> Result { let len: i16 = buf.read_i16::()?; - let mut ret = String::new(); - buf.take(len as u64).read_to_string(&mut ret)?; + let mut bytes = Vec::::new(); + buf.take(len as u64).read_to_end(&mut bytes)?; + let ret = String::from_utf8(bytes).unwrap(); Result::Ok(ret) } diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index da88f15..3f1ee80 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -275,8 +275,9 @@ impl Serializable for String { impl Serializable for format::Component { fn read_from(buf: &mut R) -> Result { let len = VarInt::read_from(buf)?.0; - let mut ret = String::new(); - buf.take(len as u64).read_to_string(&mut ret)?; + let mut bytes = Vec::::new(); + buf.take(len as u64).read_to_end(&mut bytes)?; + let ret = String::from_utf8(bytes).unwrap(); Result::Ok(Self::from_string(&ret[..])) } fn write_to(&self, buf: &mut W) -> Result<(), Error> {