Skip to content

Commit 76c787d

Browse files
committed
f drop read-side expr
1 parent 27fb4ec commit 76c787d

File tree

1 file changed

+14
-43
lines changed

1 file changed

+14
-43
lines changed

lightning/src/util/ser_macros.rs

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ macro_rules! _encode_tlv {
5454
field.write($stream)?;
5555
}
5656
};
57-
($stream: expr, $optional_type: expr, $optional_field: expr, (legacy, $fieldty: ty, $read: expr, $write: expr)) => {
57+
($stream: expr, $optional_type: expr, $optional_field: expr, (legacy, $fieldty: ty, $write: expr)) => {
5858
$crate::_encode_tlv!($stream, $optional_type, $write, option);
5959
};
6060
($stream: expr, $type: expr, $field: expr, optional_vec) => {
@@ -216,7 +216,7 @@ macro_rules! _get_varint_length_prefixed_tlv_length {
216216
$len.0 += field_len;
217217
}
218218
};
219-
($len: expr, $optional_type: expr, $optional_field: expr, (legacy, $fieldty: ty, $read: expr, $write: expr)) => {
219+
($len: expr, $optional_type: expr, $optional_field: expr, (legacy, $fieldty: ty, $write: expr)) => {
220220
$crate::_get_varint_length_prefixed_tlv_length!($len, $optional_type, $write, option);
221221
};
222222
($len: expr, $type: expr, $field: expr, optional_vec) => {
@@ -301,7 +301,7 @@ macro_rules! _check_decoded_tlv_order {
301301
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, (option, explicit_type: $fieldty: ty)) => {{
302302
// no-op
303303
}};
304-
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, (legacy, $fieldty: ty, $read: expr, $write: expr)) => {{
304+
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, (legacy, $fieldty: ty, $write: expr)) => {{
305305
// no-op
306306
}};
307307
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, (required, explicit_type: $fieldty: ty)) => {{
@@ -363,7 +363,7 @@ macro_rules! _check_missing_tlv {
363363
($last_seen_type: expr, $type: expr, $field: ident, (option, explicit_type: $fieldty: ty)) => {{
364364
// no-op
365365
}};
366-
($last_seen_type: expr, $type: expr, $field: ident, (legacy, $fieldty: ty, $read: expr, $write: expr)) => {{
366+
($last_seen_type: expr, $type: expr, $field: ident, (legacy, $fieldty: ty, $write: expr)) => {{
367367
// no-op
368368
}};
369369
($last_seen_type: expr, $type: expr, $field: ident, (required, explicit_type: $fieldty: ty)) => {{
@@ -413,7 +413,7 @@ macro_rules! _decode_tlv {
413413
let _field: &Option<$fieldty> = &$field;
414414
_decode_tlv!($outer_reader, $reader, $field, option);
415415
}};
416-
($outer_reader: expr, $reader: expr, $field: ident, (legacy, $fieldty: ty, $read: expr, $write: expr)) => {{
416+
($outer_reader: expr, $reader: expr, $field: ident, (legacy, $fieldty: ty, $write: expr)) => {{
417417
$crate::_decode_tlv!($outer_reader, $reader, $field, (option, explicit_type: $fieldty));
418418
// Note that $read is only executed in impl_writeable_tlv_based_enum_upgradable!
419419
}};
@@ -478,16 +478,6 @@ macro_rules! _decode_tlv {
478478
}};
479479
}
480480

481-
/// Runs the read side logic for legacy read types
482-
#[doc(hidden)]
483-
#[macro_export]
484-
macro_rules! _run_legacy_tlv_read_logic {
485-
($field: ident, (legacy, $fieldty: ty, $read: expr, $write: expr)) => {{
486-
$read;
487-
}};
488-
($field: ident, $fieldty: tt) => {};
489-
}
490-
491481
/// Checks if `$val` matches `$type`.
492482
/// This is exported for use by other exported macros, do not use directly.
493483
#[doc(hidden)]
@@ -569,13 +559,6 @@ macro_rules! decode_tlv_stream_with_custom_tlv_decode {
569559
#[macro_export]
570560
macro_rules! _decode_tlv_stream_range {
571561
($stream: expr, $range: expr, $rewind: ident, {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}
572-
$(, $decode_custom_tlv: expr)?) => { {
573-
$crate::_decode_tlv_stream_range!(SKIP_LEGACY, $stream, $range, $rewind, {$(($type, $field, $fieldty)),*} $(, $decode_custom_tlv)?);
574-
$({
575-
$crate::_run_legacy_tlv_read_logic!($field, $fieldty);
576-
})*
577-
} };
578-
(SKIP_LEGACY, $stream: expr, $range: expr, $rewind: ident, {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}
579562
$(, $decode_custom_tlv: expr)?) => { {
580563
use $crate::ln::msgs::DecodeError;
581564
let mut last_seen_type: Option<u64> = None;
@@ -818,7 +801,7 @@ macro_rules! _init_tlv_based_struct_field {
818801
($field: ident, option) => {
819802
$field
820803
};
821-
($field: ident, (legacy, $fieldty: ty, $read: expr, $write: expr)) => {
804+
($field: ident, (legacy, $fieldty: ty, $write: expr)) => {
822805
$crate::_init_tlv_based_struct_field!($field, option)
823806
};
824807
($field: ident, (option: $trait: ident $(, $read_arg: expr)?)) => {
@@ -872,7 +855,7 @@ macro_rules! _init_tlv_field_var {
872855
($field: ident, (option, explicit_type: $fieldty: ty)) => {
873856
let mut $field: Option<$fieldty> = None;
874857
};
875-
($field: ident, (legacy, $fieldty: ty, $read: expr, $write: expr)) => {
858+
($field: ident, (legacy, $fieldty: ty, $write: expr)) => {
876859
$crate::_init_tlv_field_var!($field, (option, explicit_type: $fieldty));
877860
};
878861
($field: ident, (required, explicit_type: $fieldty: ty)) => {
@@ -943,24 +926,12 @@ macro_rules! _ignore_arg {
943926
#[macro_export]
944927
macro_rules! _decode_and_build {
945928
($stream: ident, $thing: path, {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}) => { {
929+
$crate::_init_and_read_len_prefixed_tlv_fields!($stream, {
930+
$(($type, $field, $fieldty)),*
931+
});
946932
$(
947-
$crate::_init_tlv_field_var!($field, $fieldty);
948-
)*
949-
let tlv_len: $crate::util::ser::BigSize = $crate::util::ser::Readable::read($stream)?;
950-
let mut rd = $crate::util::ser::FixedLengthReader::new($stream, tlv_len.0);
951-
let rewind = |_, _| { unreachable!() };
952-
$crate::_decode_tlv_stream_range!(SKIP_LEGACY, &mut rd, .., rewind, {$(($type, $field, $fieldty)),*});
953-
rd.eat_remaining().map_err(|_| $crate::ln::msgs::DecodeError::ShortRead)?;
954-
// We mark fields as `mut` as we read them so that legacy post-read actions can modify them
955-
// if desired.
956-
$(
957-
#[allow(unused_mut)]
958-
let mut $field = $crate::_init_tlv_based_struct_field!($field, $fieldty);
933+
let $field = $crate::_init_tlv_based_struct_field!($field, $fieldty);
959934
)*
960-
$({
961-
$crate::_run_legacy_tlv_read_logic!($field, $fieldty);
962-
})*
963-
964935
::lightning_macros::drop_legacy_field_definition!($thing {
965936
$($field: $crate::_ignore_arg!($field, $fieldty)),*
966937
})
@@ -973,10 +944,10 @@ macro_rules! _decode_and_build {
973944
/// If `$fieldty` is `option`, then `$field` is optional field.
974945
/// If `$fieldty` is `optional_vec`, then `$field` is a [`Vec`], which needs to have its individual elements serialized.
975946
/// Note that for `optional_vec` no bytes are written if the vec is empty
976-
/// If `$fieldty` is `(legacy, $ty, $read, $write)` then, when writing, the expression $write will
947+
/// If `$fieldty` is `(legacy, $ty, $write)` then, when writing, the expression $write will
977948
/// be called which returns an `Option` and is written as a TLV if `Some`. When reading, an
978-
/// optional field of type `$ty` is read. The code in `$read` is always executed after all TLVs
979-
/// have been read.
949+
/// optional field of type `$ty` is read (which can be used in later `default_value` or
950+
/// `static_value` fields).
980951
///
981952
/// For example,
982953
/// ```

0 commit comments

Comments
 (0)