From 52f530f8c19ae248480d4b42f945083cbee0b80e Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Sat, 17 Aug 2024 20:18:03 -0700 Subject: [PATCH] Add yunq support for nested messages. --- rust/lib/yunq-derive/src/lib.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/rust/lib/yunq-derive/src/lib.rs b/rust/lib/yunq-derive/src/lib.rs index cf72f4a..d1652e0 100644 --- a/rust/lib/yunq-derive/src/lib.rs +++ b/rust/lib/yunq-derive/src/lib.rs @@ -33,10 +33,16 @@ fn serialize_field(name: &Ident, ind: usize, path: &Path) -> proc_macro2::TokenS } } } else { - panic!( - "Serialization not implemented for: {}", - path.to_token_stream() - ) + quote! { + { + let msg_offset = next_extension; + let msg_length = self.#name.serialize(buf, offset + next_extension as usize, caps)? as u32; + next_extension += msg_length; + + buf.write_at(yunq::message::field_offset(offset, #ind), msg_offset)?; + buf.write_at(yunq::message::field_offset(offset, #ind) + 4, msg_length)?; + } + } } } @@ -62,7 +68,13 @@ fn parse_field(name: &Ident, ind: usize, path: &Path) -> proc_macro2::TokenStrea let #name = buf.at::(yunq::message::field_offset(offset, #ind))?; } } else { - panic!("Parsing not implemented for: {}", path.into_token_stream()); + quote! { + let #name = { + let msg_offset = buf.at::(yunq::message::field_offset(offset, #ind))? as usize; + + #path::parse(buf, offset + msg_offset, caps)? + }; + } } }