utf16 handling when parsing string bytes

This commit is contained in:
Jake Probst 2019-06-23 17:07:02 -07:00
parent 67b56be4f6
commit f5c19ad66b

View File

@ -172,13 +172,17 @@ pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream {
"String" => {
from_bytes.push(quote! {
#ident: {
let mut s = String::new();
if let Ok(len) = cur.read_to_string(&mut s) {
let mut s: Vec<u8> = Vec::new();
if let Ok(len) = cur.read_to_end(&mut s) {
}
else {
return Err(PacketParseError::NotEnoughBytes);
};
s
let mut utf16 = Vec::new();
for c in s.chunks(2) {
utf16.push(u16::from_le_bytes([c[0], c[1]]));
}
String::from_utf16_lossy(utf16.as_slice())
},
});
},