X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=lightning%2Fsrc%2Futil%2Fser_macros.rs;h=73c4015726191f5ae5ec8b95eadcf82101bc3af8;hb=a4df59b37711215ece62ee8da3d2c5d9b537de4e;hp=db7553d5ff8e3dea88b206bc462011e1c8d96f22;hpb=94a07d9caee6d38d42954ac783c49afe1cf89697;p=rust-lightning diff --git a/lightning/src/util/ser_macros.rs b/lightning/src/util/ser_macros.rs index db7553d5..73c40157 100644 --- a/lightning/src/util/ser_macros.rs +++ b/lightning/src/util/ser_macros.rs @@ -431,6 +431,18 @@ macro_rules! init_tlv_field_var { }; } +macro_rules! init_and_read_tlv_fields { + ($reader: ident, {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}) => { + $( + init_tlv_field_var!($field, $fieldty); + )* + + read_tlv_fields!($reader, { + $(($type, $field, $fieldty)),* + }); + } +} + /// Implements Readable/Writeable for a struct storing it as a set of TLVs /// If $fieldty is `required`, then $field is a required field that is not an Option nor a Vec. /// If $fieldty is `option`, then $field is optional field. @@ -465,10 +477,7 @@ macro_rules! impl_writeable_tlv_based { impl $crate::util::ser::Readable for $st { fn read(reader: &mut R) -> Result { - $( - init_tlv_field_var!($field, $fieldty); - )* - read_tlv_fields!(reader, { + init_and_read_tlv_fields!(reader, { $(($type, $field, $fieldty)),* }); Ok(Self { @@ -495,15 +504,15 @@ macro_rules! tlv_stream { $(($type:expr, $field:ident : $fieldty:tt)),* $(,)* }) => { #[derive(Debug)] - pub(crate) struct $name { + pub(super) struct $name { $( - $field: Option, + pub(super) $field: Option, )* } - pub(crate) struct $nameref<'a> { + pub(super) struct $nameref<'a> { $( - pub(crate) $field: Option, + pub(super) $field: Option, )* } @@ -605,10 +614,7 @@ macro_rules! impl_writeable_tlv_based_enum_upgradable { // Because read_tlv_fields creates a labeled loop, we cannot call it twice // in the same function body. Instead, we define a closure and call it. let f = || { - $( - init_tlv_field_var!($field, $fieldty); - )* - read_tlv_fields!(reader, { + init_and_read_tlv_fields!(reader, { $(($type, $field, $fieldty)),* }); Ok(Some($st::$variant_name { @@ -658,10 +664,7 @@ macro_rules! impl_writeable_tlv_based_enum { // Because read_tlv_fields creates a labeled loop, we cannot call it twice // in the same function body. Instead, we define a closure and call it. let f = || { - $( - init_tlv_field_var!($field, $fieldty); - )* - read_tlv_fields!(reader, { + init_and_read_tlv_fields!(reader, { $(($type, $field, $fieldty)),* }); Ok($st::$variant_name { @@ -676,7 +679,7 @@ macro_rules! impl_writeable_tlv_based_enum { Ok($st::$tuple_variant_name(Readable::read(reader)?)) }),* _ => { - Err(DecodeError::UnknownRequiredFeature) + Err($crate::ln::msgs::DecodeError::UnknownRequiredFeature) }, } }