Browse Source

clean up pso_packet

pull/3/head
jake 5 years ago
parent
commit
c5ffa5bbcf
  1. 15
      psopacket/src/lib.rs

15
psopacket/src/lib.rs

@ -9,7 +9,7 @@ use quote::quote;
#[proc_macro_attribute] #[proc_macro_attribute]
pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream { pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream {
let arg = parse_macro_input!(attr as syn::LitInt); let arg = parse_macro_input!(attr as syn::LitInt);
let pkt_cmd = arg.value() as u16;
let pkt_cmd = arg.base10_parse::<u16>().unwrap();
let parsed = parse_macro_input!(item as ItemStruct); let parsed = parse_macro_input!(item as ItemStruct);
@ -26,7 +26,7 @@ pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream {
syn::Type::Array(arr) => { syn::Type::Array(arr) => {
let array_length = if let syn::Expr::Lit(lit) = &arr.len { let array_length = if let syn::Expr::Lit(lit) = &arr.len {
if let syn::Lit::Int(int) = &lit.lit { if let syn::Lit::Int(int) = &lit.lit {
int.value() as usize
int.base10_parse::<usize>().unwrap()
} }
else { else {
return syn::Error::new(arr.bracket_token.span, "unknown array size").to_compile_error().into(); return syn::Error::new(arr.bracket_token.span, "unknown array size").to_compile_error().into();
@ -50,14 +50,6 @@ pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream {
write!(f, " {}: {:?}\n", #ident_str, self.#ident.to_vec()).unwrap(); write!(f, " {}: {:?}\n", #ident_str, self.#ident.to_vec()).unwrap();
}); });
} }
//dbg_write_vars.push(quote! {
//write!(f, " {}: {:?}\n", #ident_str, self.#ident.iter()).unwrap();
/*match std::str::from_utf8(&self.#ident) {
Ok(v) => write!(f, " {}: {:?}\n", #ident_str, v).unwrap(),
Err(_) => write!(f, " {}: {:?}\n", #ident_str, self.#ident.iter()).unwrap()
}*/
//write!(f, " {}: {:?}\n", #ident_str, var_as_str).unwrap();
//});
as_bytes.push(quote! { as_bytes.push(quote! {
for f in self.#ident.iter() { for f in self.#ident.iter() {
buf.extend_from_slice(&f.to_le_bytes()) buf.extend_from_slice(&f.to_le_bytes())
@ -143,7 +135,6 @@ pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream {
for c in self.#ident.as_str().encode_utf16() { for c in self.#ident.as_str().encode_utf16() {
buf.extend_from_slice(&c.to_le_bytes()); buf.extend_from_slice(&c.to_le_bytes());
} }
//buf.extend_from_slice(&self.#ident.as_str().encode_utf16());
}); });
} }
_ => { _ => {
@ -235,8 +226,6 @@ pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream {
#path::from_le_bytes(b)? #path::from_le_bytes(b)?
}, },
}); });
//return syn::Error::new(path.path.segments[0].ident.span(), "type not supported")
// .to_compile_error().into();
} }
} }
partialeq.push(quote! { partialeq.push(quote! {

Loading…
Cancel
Save