#[allow(unused_comparisons)] // Note that $type may be 0 making the second comparison always true
let invalid_order = ($last_seen_type.is_none() || $last_seen_type.unwrap() < $type) && $typ.0 > $type;
if invalid_order {
- $field = $default;
+ $field = $default.into();
}
}};
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, required) => {{
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, ignorable) => {{
// no-op
}};
+ ($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, (option: $trait: ident $(, $read_arg: expr)?)) => {{
+ // no-op
+ }};
}
macro_rules! check_missing_tlv {
#[allow(unused_comparisons)] // Note that $type may be 0 making the second comparison always true
let missing_req_type = $last_seen_type.is_none() || $last_seen_type.unwrap() < $type;
if missing_req_type {
- $field = $default;
+ $field = $default.into();
}
}};
($last_seen_type: expr, $type: expr, $field: ident, required) => {{
($last_seen_type: expr, $type: expr, $field: ident, ignorable) => {{
// no-op
}};
+ ($last_seen_type: expr, $type: expr, $field: ident, (option: $trait: ident $(, $read_arg: expr)?)) => {{
+ // no-op
+ }};
}
macro_rules! decode_tlv {
($reader: expr, $field: ident, ignorable) => {{
$field = ser::MaybeReadable::read(&mut $reader)?;
}};
+ ($reader: expr, $field: ident, (option: $trait: ident $(, $read_arg: expr)?)) => {{
+ $field = Some($trait::read(&mut $reader $(, $read_arg)*)?);
+ }};
}
macro_rules! decode_tlv_stream {
/// correctly.
macro_rules! write_tlv_fields {
($stream: expr, {$(($type: expr, $field: expr, $fieldty: tt)),* $(,)*}) => {
- encode_varint_length_prefixed_tlv!($stream, {$(($type, $field, $fieldty)),*});
+ encode_varint_length_prefixed_tlv!($stream, {$(($type, $field, $fieldty)),*})
}
}
macro_rules! init_tlv_based_struct_field {
($field: ident, (default_value, $default: expr)) => {
- $field
+ $field.0.unwrap()
};
($field: ident, option) => {
$field
macro_rules! init_tlv_field_var {
($field: ident, (default_value, $default: expr)) => {
- let mut $field = $default;
+ let mut $field = ::util::ser::OptionDeserWrapper(None);
};
($field: ident, required) => {
let mut $field = ::util::ser::OptionDeserWrapper(None);
macro_rules! impl_writeable_tlv_based_enum_upgradable {
($st: ident, $(($variant_id: expr, $variant_name: ident) =>
{$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}
- ),* $(,)*) => {
+ ),* $(,)*
+ $(;
+ $(($tuple_variant_id: expr, $tuple_variant_name: ident)),* $(,)*)*) => {
_impl_writeable_tlv_based_enum_common!($st,
- $(($variant_id, $variant_name) => {$(($type, $field, $fieldty)),*}),*; );
+ $(($variant_id, $variant_name) => {$(($type, $field, $fieldty)),*}),*;
+ $($(($tuple_variant_id, $tuple_variant_name)),*)*);
impl ::util::ser::MaybeReadable for $st {
fn read<R: $crate::io::Read>(reader: &mut R) -> Result<Option<Self>, ::ln::msgs::DecodeError> {
};
f()
}),*
+ $($($tuple_variant_id => {
+ Ok(Some($st::$tuple_variant_name(Readable::read(reader)?)))
+ }),*)*
_ if id % 2 == 1 => Ok(None),
_ => Err(DecodeError::UnknownRequiredFeature),
}