]> git.bitcoin.ninja Git - rust-lightning/commitdiff
ser_macros: support messages with no fields
authorValentine Wallace <vwallace@protonmail.com>
Wed, 5 Jun 2024 17:06:11 +0000 (13:06 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Thu, 13 Jun 2024 16:20:43 +0000 (12:20 -0400)
lightning/src/util/ser_macros.rs

index 740b7c12561ce8466d1a2e30f56faacc797961ac..255fd3ebc327899c98bc599a4a3213834179bb79 100644 (file)
@@ -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);
+       }
 }