utf16 handling when parsing string bytes
This commit is contained in:
parent
67b56be4f6
commit
f5c19ad66b
@ -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();
|
let mut s: Vec<u8> = Vec::new();
|
||||||
if let Ok(len) = cur.read_to_string(&mut s) {
|
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…
x
Reference in New Issue
Block a user