From: Valentine Wallace Date: Wed, 5 Jun 2024 17:06:11 +0000 (-0400) Subject: ser_macros: support messages with no fields X-Git-Tag: v0.0.124-beta~70^2~6 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=66df3292365182fb7e34aca730a678c67a68e6a9;p=rust-lightning ser_macros: support messages with no fields --- 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); + } }