};
}
+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.
impl $crate::util::ser::Readable for $st {
fn read<R: $crate::io::Read>(reader: &mut R) -> Result<Self, $crate::ln::msgs::DecodeError> {
- $(
- init_tlv_field_var!($field, $fieldty);
- )*
- read_tlv_fields!(reader, {
+ init_and_read_tlv_fields!(reader, {
$(($type, $field, $fieldty)),*
});
Ok(Self {
$(($type:expr, $field:ident : $fieldty:tt)),* $(,)*
}) => {
#[derive(Debug)]
- pub(crate) struct $name {
+ pub(super) struct $name {
$(
- $field: Option<tlv_record_type!($fieldty)>,
+ pub(super) $field: Option<tlv_record_type!($fieldty)>,
)*
}
- pub(crate) struct $nameref<'a> {
+ pub(super) struct $nameref<'a> {
$(
- pub(crate) $field: Option<tlv_record_ref_type!($fieldty)>,
+ pub(super) $field: Option<tlv_record_ref_type!($fieldty)>,
)*
}
// 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 {
// 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 {
Ok($st::$tuple_variant_name(Readable::read(reader)?))
}),*
_ => {
- Err(DecodeError::UnknownRequiredFeature)
+ Err($crate::ln::msgs::DecodeError::UnknownRequiredFeature)
},
}
}