use ln::features::OfferFeatures;
use ln::msgs::MAX_VALUE_MSAT;
use onion_message::BlindedPath;
-use util::ser::{Writeable, Writer};
+use util::ser::{HighZeroBytesDroppedBigSize, WithoutLength, Writeable, Writer};
use prelude::*;
pub type CurrencyCode = [u8; 3];
tlv_stream!(OfferTlvStream, OfferTlvStreamRef, {
- (2, chains: Vec<ChainHash>),
- (4, metadata: Vec<u8>),
+ (2, chains: (Vec<ChainHash>, WithoutLength)),
+ (4, metadata: (Vec<u8>, WithoutLength)),
(6, currency: CurrencyCode),
- (8, amount: u64),
- (10, description: String),
+ (8, amount: (u64, HighZeroBytesDroppedBigSize)),
+ (10, description: (String, WithoutLength)),
(12, features: OfferFeatures),
- (14, absolute_expiry: u64),
- (16, paths: Vec<BlindedPath>),
- (18, issuer: String),
- (20, quantity_min: u64),
- (22, quantity_max: u64),
+ (14, absolute_expiry: (u64, HighZeroBytesDroppedBigSize)),
+ (16, paths: (Vec<BlindedPath>, WithoutLength)),
+ (18, issuer: (String, WithoutLength)),
+ (20, quantity_min: (u64, HighZeroBytesDroppedBigSize)),
+ (22, quantity_max: (u64, HighZeroBytesDroppedBigSize)),
(24, node_id: PublicKey),
});
field.write($stream)?;
}
};
- ($stream: expr, $type: expr, $field: expr, (tlv_record, $fieldty:ident$(<$gen:ident>)?)) => {
+ ($stream: expr, $type: expr, $field: expr, (tlv_record, $fieldty:tt)) => {
if let Some(field) = $field {
- let field: encoded_tlv_record_ref_type!($fieldty$(<$gen>)?) = From::from(field);
+ let field: encoded_tlv_record_ref_type!($fieldty) = From::from(field);
BigSize($type).write($stream)?;
BigSize(field.serialized_length() as u64).write($stream)?;
field.write($stream)?;
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, (option: $trait: ident $(, $read_arg: expr)?)) => {{
// no-op
}};
- ($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, (tlv_record, $fieldty:ident$(<$gen:ident>)?)) => {{
+ ($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, (tlv_record, $fieldty:tt)) => {{
// no-op
}};
}
($last_seen_type: expr, $type: expr, $field: ident, (option: $trait: ident $(, $read_arg: expr)?)) => {{
// no-op
}};
- ($last_seen_type: expr, $type: expr, $field: ident, (tlv_record, $fieldty:ident$(<$gen:ident>)?)) => {{
+ ($last_seen_type: expr, $type: expr, $field: ident, (tlv_record, $fieldty:tt)) => {{
// no-op
}};
}
($reader: expr, $field: ident, (option: $trait: ident $(, $read_arg: expr)?)) => {{
$field = Some($trait::read(&mut $reader $(, $read_arg)*)?);
}};
- ($reader: expr, $field: ident, (tlv_record, $fieldty:ident$(<$gen:ident>)?)) => {{
+ ($reader: expr, $field: ident, (tlv_record, $fieldty:tt)) => {{
$field = {
- let field: encoded_tlv_record_type!($fieldty$(<$gen>)?) =
- ser::Readable::read(&mut $reader)?;
+ let field: encoded_tlv_record_type!($fieldty) = ser::Readable::read(&mut $reader)?;
Some(field.into())
};
}};
/// [`Writeable`]: crate::util::ser::Writeable
macro_rules! tlv_stream {
($name:ident, $nameref:ident, {
- $(($type:expr, $field:ident : $fieldty:ident$(<$gen:ident>)?)),* $(,)*
+ $(($type:expr, $field:ident : $fieldty:tt)),* $(,)*
}) => {
#[derive(Debug)]
struct $name {
$(
- $field: Option<$fieldty$(<$gen>)?>,
+ $field: Option<tlv_record_type!($fieldty)>,
)*
}
pub(crate) struct $nameref<'a> {
$(
- pub(crate) $field: Option<tlv_record_ref_type!($fieldty$(<$gen>)?)>,
+ pub(crate) $field: Option<tlv_record_ref_type!($fieldty)>,
)*
}
impl<'a> ::util::ser::Writeable for $nameref<'a> {
fn write<W: ::util::ser::Writer>(&self, writer: &mut W) -> Result<(), $crate::io::Error> {
encode_tlv_stream!(writer, {
- $(($type, self.$field, (tlv_record, $fieldty$(<$gen>)?))),*
+ $(($type, self.$field, (tlv_record, $fieldty))),*
});
Ok(())
}
init_tlv_field_var!($field, tlv_record);
)*
decode_tlv_stream!(reader, {
- $(($type, $field, (tlv_record, $fieldty$(<$gen>)?))),*
+ $(($type, $field, (tlv_record, $fieldty))),*
});
Ok(Self {
}
}
+macro_rules! tlv_record_type {
+ (($type:ty, $wrapper:ident)) => {
+ $type
+ };
+ ($type:ty) => {
+ $type
+ };
+}
+
macro_rules! tlv_record_ref_type {
(u8) => {
u8
};
- (u16) => {
- u16
- };
- (u32) => {
- u32
- };
- (u64) => {
- u64
- };
(char) => {
char
};
- (String) => {
- &'a crate::prelude::String
+ (($type:ty, HighZeroBytesDroppedBigSize)) => {
+ $type
};
- (Vec<$type:ty>) => {
- &'a crate::prelude::Vec<$type>
+ (($type:ty, $wrapper:ident)) => {
+ &'a $type
};
- ($type:ident$(<$gen:ident>)?) => {
- &'a $type$(<$gen>)?
+ ($type:ty) => {
+ &'a $type
};
}
macro_rules! encoded_tlv_record_type {
- (u8) => {
- u8
- };
- (u16) => {
- ::util::ser::HighZeroBytesDroppedBigSize<u16>
+ (($type:ty, $wrapper:ident)) => {
+ $wrapper<$type>
};
- (u32) => {
- ::util::ser::HighZeroBytesDroppedBigSize<u32>
- };
- (u64) => {
- ::util::ser::HighZeroBytesDroppedBigSize<u64>
- };
- (char) => {
- char
- };
- (String) => {
- ::util::ser::WithoutLength<crate::prelude::String>
- };
- (Vec<$type:ty>) => {
- ::util::ser::WithoutLength<crate::prelude::Vec<$type>>
- };
- ($type:ident$(<$gen:ident>)?) => {
- $type$(<$gen>)?
+ ($type:ty) => {
+ $type
};
}
(u8) => {
u8
};
- (u16) => {
- ::util::ser::HighZeroBytesDroppedBigSize<u16>
- };
- (u32) => {
- ::util::ser::HighZeroBytesDroppedBigSize<u32>
- };
- (u64) => {
- ::util::ser::HighZeroBytesDroppedBigSize<u64>
- };
(char) => {
char
};
- (String) => {
- ::util::ser::WithoutLength<&crate::prelude::String>
+ (($type:ty, HighZeroBytesDroppedBigSize)) => {
+ HighZeroBytesDroppedBigSize<$type>
};
- (Vec<$type:ty>) => {
- ::util::ser::WithoutLength<&crate::prelude::Vec<$type>>
+ (($type:ty, $wrapper:ident)) => {
+ $wrapper<&$type>
};
- ($type:ident$(<$gen:ident>)?) => {
- &$type$(<$gen>)?
+ ($type:ty) => {
+ &$type
};
}