|
@ -37,17 +37,35 @@ pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream { |
|
|
};
|
|
|
};
|
|
|
match *arr.elem {
|
|
|
match *arr.elem {
|
|
|
syn::Type::Path(ref path) => {
|
|
|
syn::Type::Path(ref path) => {
|
|
|
dbg_write_vars.push(quote! {
|
|
|
|
|
|
write!(f, " {}: {:?}\n", #ident_str, self.#ident.iter()).unwrap();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
let ty = path.path.segments[0].ident.to_string();
|
|
|
|
|
|
if ty.as_str() == "u8_str" {
|
|
|
|
|
|
dbg_write_vars.push(quote! {
|
|
|
|
|
|
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()
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
dbg_write_vars.push(quote! {
|
|
|
|
|
|
write!(f, " {}: {:?}\n", #ident_str, self.#ident.iter()).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())
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
let ty = path.path.segments[0].ident.to_string();
|
|
|
|
|
|
match ty.as_str() {
|
|
|
match ty.as_str() {
|
|
|
"u8" => {
|
|
|
|
|
|
|
|
|
"u8" | "u8_str" => {
|
|
|
from_bytes.push(quote! {
|
|
|
from_bytes.push(quote! {
|
|
|
#ident: {
|
|
|
#ident: {
|
|
|
let mut b: [u8; #array_length] = [0; #array_length];
|
|
|
let mut b: [u8; #array_length] = [0; #array_length];
|
|
@ -88,7 +106,7 @@ pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream { |
|
|
});
|
|
|
});
|
|
|
let ty = path.path.segments[0].ident.to_string();
|
|
|
let ty = path.path.segments[0].ident.to_string();
|
|
|
match ty.as_str() {
|
|
|
match ty.as_str() {
|
|
|
"u8" => {
|
|
|
|
|
|
|
|
|
"u8" | "u8_str" => {
|
|
|
from_bytes.push(quote! {
|
|
|
from_bytes.push(quote! {
|
|
|
#ident: {
|
|
|
#ident: {
|
|
|
let mut b: [u8; 1] = [0; 1];
|
|
|
let mut b: [u8; 1] = [0; 1];
|
|
@ -178,9 +196,9 @@ pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream { |
|
|
impl PSOPacket for #this_struct {
|
|
|
impl PSOPacket for #this_struct {
|
|
|
fn from_bytes(data: &Vec<u8>) -> Result<#this_struct, PacketParseError> {
|
|
|
fn from_bytes(data: &Vec<u8>) -> Result<#this_struct, PacketParseError> {
|
|
|
let mut cur = std::io::Cursor::new(data);
|
|
|
let mut cur = std::io::Cursor::new(data);
|
|
|
cur.seek(SeekFrom::Start(2));
|
|
|
|
|
|
|
|
|
cur.seek(SeekFrom::Start(2)).unwrap();
|
|
|
let mut b: [u8; 2] = [0; 2];
|
|
|
let mut b: [u8; 2] = [0; 2];
|
|
|
cur.read(&mut b);
|
|
|
|
|
|
|
|
|
cur.read(&mut b).unwrap();
|
|
|
let cmd = u16::from_le_bytes(b);
|
|
|
let cmd = u16::from_le_bytes(b);
|
|
|
|
|
|
|
|
|
if cmd != #pkt_cmd {
|
|
|
if cmd != #pkt_cmd {
|
|
@ -188,10 +206,10 @@ pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
if #has_flag {
|
|
|
if #has_flag {
|
|
|
cur.seek(SeekFrom::Start(4));
|
|
|
|
|
|
|
|
|
cur.seek(SeekFrom::Start(4)).unwrap();
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
else {
|
|
|
cur.seek(SeekFrom::Start(8));
|
|
|
|
|
|
|
|
|
cur.seek(SeekFrom::Start(8)).unwrap();
|
|
|
}
|
|
|
}
|
|
|
Ok(#this_struct {
|
|
|
Ok(#this_struct {
|
|
|
#(#from_bytes)*
|
|
|
#(#from_bytes)*
|
|
|