Browse Source

utf16 handling when parsing string bytes

pull/3/head
Jake Probst 6 years ago
parent
commit
f5c19ad66b
  1. 10
      psopacket/src/lib.rs

10
psopacket/src/lib.rs

@ -172,13 +172,17 @@ pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream {
"String" => { "String" => {
from_bytes.push(quote! { from_bytes.push(quote! {
#ident: { #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 { else {
return Err(PacketParseError::NotEnoughBytes); 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())
}, },
}); });
}, },

Loading…
Cancel
Save