From 66df3292365182fb7e34aca730a678c67a68e6a9 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Wed, 5 Jun 2024 13:06:11 -0400 Subject: [PATCH] ser_macros: support messages with no fields --- lightning/src/util/ser_macros.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lightning/src/util/ser_macros.rs b/lightning/src/util/ser_macros.rs index 740b7c125..255fd3ebc 100644 --- a/lightning/src/util/ser_macros.rs +++ b/lightning/src/util/ser_macros.rs @@ -633,7 +633,7 @@ macro_rules! impl_writeable_msg { $($crate::_init_tlv_field_var!($tlvfield, $fieldty);)* $crate::decode_tlv_stream!(r, {$(($type, $tlvfield, $fieldty)),*}); Ok(Self { - $($field),*, + $($field,)* $($tlvfield),* }) } @@ -1531,4 +1531,18 @@ mod tests { fn simple_test_tlv_write() { do_simple_test_tlv_write().unwrap(); } + + #[derive(Debug, Eq, PartialEq)] + struct EmptyMsg {} + impl_writeable_msg!(EmptyMsg, {}, {}); + + #[test] + fn impl_writeable_msg_empty() { + let msg = EmptyMsg {}; + let mut encoded_msg = msg.encode(); + assert!(encoded_msg.is_empty()); + let mut encoded_msg_stream = Cursor::new(&mut encoded_msg); + let decoded_msg: EmptyMsg = Readable::read(&mut encoded_msg_stream).unwrap(); + assert_eq!(msg, decoded_msg); + } } -- 2.39.5