Browse Source

pso_packet: u16 and u32 arrays

pull/3/head
jake 5 years ago
parent
commit
48599ee116
  1. 5
      psopacket/Cargo.toml
  2. 34
      psopacket/src/lib.rs

5
psopacket/Cargo.toml

@ -8,5 +8,6 @@ edition = "2018"
proc-macro = true
[dependencies]
syn = {version = "0.15", features=["full", "extra-traits", "parsing"]}
quote = "0.6"
syn = {version = "1.0", features=["full", "extra-traits", "parsing"]}
quote = "1.0"
proc-macro2 = "1.0"

34
psopacket/src/lib.rs

@ -80,6 +80,40 @@ pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream {
},
});
},
"u16" => {
from_bytes.push(quote! {
#ident: {
let mut b: [u16; #array_length] = [0; #array_length];
if let Ok(len) = cur.read(&mut b) {
if len != #array_length {
return Err(PacketParseError::NotEnoughBytes);
}
}
else {
return Err(PacketParseError::NotEnoughBytes);
};
b
},
});
},
"u32" => {
from_bytes.push(quote! {
#ident: {
let mut b: [u32; #array_length] = [0; #array_length];
if let Ok(len) = cur.read(&mut b) {
if len != #array_length {
return Err(PacketParseError::NotEnoughBytes);
}
}
else {
return Err(PacketParseError::NotEnoughBytes);
};
b
},
});
},
_ => {
return syn::Error::new(path.path.segments[0].ident.span(), "type not supported")
.to_compile_error().into();

Loading…
Cancel
Save