X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Fser_macros.rs;h=816426b1133cb21a1e703129e6aecfa884f2c00c;hb=a600eee87c96ee8865402e86bb1865011bf2d2de;hp=b80ca537bbf03bd86d07912687d32ce81cd11f81;hpb=2352587811afd37034ff23aba4de98d5efa4e220;p=rust-lightning diff --git a/lightning/src/util/ser_macros.rs b/lightning/src/util/ser_macros.rs index b80ca537..816426b1 100644 --- a/lightning/src/util/ser_macros.rs +++ b/lightning/src/util/ser_macros.rs @@ -118,6 +118,9 @@ macro_rules! check_tlv_order { ($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 { @@ -144,6 +147,9 @@ macro_rules! check_missing_tlv { ($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 { @@ -163,6 +169,9 @@ 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 { @@ -310,7 +319,7 @@ macro_rules! write_ver_prefix { /// 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)),*}) } } @@ -455,9 +464,12 @@ macro_rules! _impl_writeable_tlv_based_enum_common { 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(reader: &mut R) -> Result, ::ln::msgs::DecodeError> { @@ -481,6 +493,9 @@ macro_rules! impl_writeable_tlv_based_enum_upgradable { }; f() }),* + $($($tuple_variant_id => { + Ok(Some($st::$tuple_variant_name(Readable::read(reader)?))) + }),*)* _ if id % 2 == 1 => Ok(None), _ => Err(DecodeError::UnknownRequiredFeature), }