From a8b5559ac01dec2cb6b19751c3b31190f1cd8a11 Mon Sep 17 00:00:00 2001 From: Jake Probst Date: Sun, 28 Jul 2019 23:27:24 -0700 Subject: [PATCH] serialize any type that provides information on how to --- psopacket/src/lib.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/psopacket/src/lib.rs b/psopacket/src/lib.rs index cb0a04d..91d4b97 100644 --- a/psopacket/src/lib.rs +++ b/psopacket/src/lib.rs @@ -187,8 +187,22 @@ pub fn pso_packet(attr: TokenStream, item: TokenStream) -> TokenStream { }); }, _ => { - return syn::Error::new(path.path.segments[0].ident.span(), "type not supported") - .to_compile_error().into(); + from_bytes.push(quote! { + #ident: { + let mut b: [u8; #path::SIZE] = [0; #path::SIZE]; + if let Ok(len) = cur.read(&mut b) { + if len != #path::SIZE { + return Err(PacketParseError::NotEnoughBytes); + } + } + else { + return Err(PacketParseError::NotEnoughBytes); + }; + #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! {