diff --git a/psopacket/Cargo.toml b/psopacket/Cargo.toml index 72cb2bd..1276634 100644 --- a/psopacket/Cargo.toml +++ b/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" diff --git a/psopacket/src/lib.rs b/psopacket/src/lib.rs index cc621c4..b60040d 100644 --- a/psopacket/src/lib.rs +++ b/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();