mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-03-15 15:39:09 +01:00
Add new _init_and_read_tlv_stream ser macro
Useful for when you want to use _init_and_read_len_prefixed_tlv_fields but there is no length byte at the start of the TLV stream.
This commit is contained in:
parent
4a30d9e78a
commit
cf64e3fba5
2 changed files with 17 additions and 7 deletions
|
@ -274,19 +274,16 @@ pub(crate) enum ControlTlvs {
|
|||
}
|
||||
|
||||
impl Readable for ControlTlvs {
|
||||
fn read<R: Read>(mut r: &mut R) -> Result<Self, DecodeError> {
|
||||
let mut _padding: Option<Padding> = None;
|
||||
let mut _short_channel_id: Option<u64> = None;
|
||||
let mut next_node_id: Option<PublicKey> = None;
|
||||
let mut path_id: Option<[u8; 32]> = None;
|
||||
let mut next_blinding_override: Option<PublicKey> = None;
|
||||
decode_tlv_stream!(&mut r, {
|
||||
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
|
||||
_init_and_read_tlv_stream!(r, {
|
||||
(1, _padding, option),
|
||||
(2, _short_channel_id, option),
|
||||
(4, next_node_id, option),
|
||||
(6, path_id, option),
|
||||
(8, next_blinding_override, option),
|
||||
});
|
||||
let _padding: Option<Padding> = _padding;
|
||||
let _short_channel_id: Option<u64> = _short_channel_id;
|
||||
|
||||
let valid_fwd_fmt = next_node_id.is_some() && path_id.is_none();
|
||||
let valid_recv_fmt = next_node_id.is_none() && next_blinding_override.is_none();
|
||||
|
|
|
@ -806,6 +806,19 @@ macro_rules! _init_and_read_len_prefixed_tlv_fields {
|
|||
}
|
||||
}
|
||||
|
||||
/// Equivalent to running [`_init_tlv_field_var`] then [`decode_tlv_stream`].
|
||||
macro_rules! _init_and_read_tlv_stream {
|
||||
($reader: ident, {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}) => {
|
||||
$(
|
||||
$crate::_init_tlv_field_var!($field, $fieldty);
|
||||
)*
|
||||
|
||||
$crate::decode_tlv_stream!($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 `(default_value, $default)`, then `$field` will be set to `$default` if not present.
|
||||
|
|
Loading…
Add table
Reference in a new issue