tlv_stream!(OfferTlvStream, OfferTlvStreamRef, {
(2, chains: (Vec<ChainHash>, WithoutLength)),
(4, metadata: (Vec<u8>, WithoutLength)),
- (6, currency: CurrencyCode),
+ (6, currency: (CurrencyCode)),
(8, amount: (u64, HighZeroBytesDroppedBigSize)),
(10, description: (String, WithoutLength)),
- (12, features: OfferFeatures),
+ (12, features: (OfferFeatures)),
(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),
+ (24, node_id: (PublicKey)),
});
#[cfg(test)]
field.write($stream)?;
}
};
- ($stream: expr, $type: expr, $field: expr, (tlv_record, $fieldty:tt)) => {
- if let Some(field) = $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)?;
- }
- };
}
macro_rules! encode_tlv_stream {
}
}
+macro_rules! _tlv_stream_impl_writeable {
+ ($nameref:ident, {
+ $(($type:expr, $field:ident : ($fieldty: ty $(, $serwrapper: ident)?))),* $(,)*
+ }) => {
+ 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 $(.map(|a| $serwrapper(a)))?, option)),*
+ });
+ Ok(())
+ }
+ }
+ }
+}
+
+
/// Defines a struct for a TLV stream and a similar struct using references for non-primitive types,
/// implementing [`Readable`] for the former and [`Writeable`] for the latter. Useful as an
/// intermediary format when reading or writing a type encoded as a TLV stream. Note that each field
)*
}
- 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))),*
- });
- Ok(())
- }
- }
+ _tlv_stream_impl_writeable!($nameref, {$(($type, $field: $fieldty)),*});
impl ::util::ser::Readable for $name {
fn read<R: $crate::io::Read>(reader: &mut R) -> Result<Self, ::ln::msgs::DecodeError> {
(($type:ty, $wrapper:ident)) => {
$type
};
- ($type:ty) => {
+ (($type:ty)) => {
$type
};
}
macro_rules! tlv_record_ref_type {
- (u8) => {
+ ((u8)) => {
u8
};
- (char) => {
+ ((char)) => {
char
};
- (($type:ty, HighZeroBytesDroppedBigSize)) => {
- $type
- };
+ ((u8, $wrapper: ident)) => { u8 };
+ ((u16, $wrapper: ident)) => { u16 };
+ ((u32, $wrapper: ident)) => { u32 };
+ ((u64, $wrapper: ident)) => { u64 };
(($type:ty, $wrapper:ident)) => {
&'a $type
};
- ($type:ty) => {
+ (($type:ty)) => {
&'a $type
};
}
(($type:ty, $wrapper:ident)) => {
$wrapper<$type>
};
- ($type:ty) => {
+ (($type:ty)) => {
$type
};
}
-macro_rules! encoded_tlv_record_ref_type {
- (u8) => {
- u8
- };
- (char) => {
- char
- };
- (($type:ty, HighZeroBytesDroppedBigSize)) => {
- HighZeroBytesDroppedBigSize<$type>
- };
- (($type:ty, $wrapper:ident)) => {
- $wrapper<&$type>
- };
- ($type:ty) => {
- &$type
- };
-}
-
macro_rules! _impl_writeable_tlv_based_enum_common {
($st: ident, $(($variant_id: expr, $variant_name: ident) =>
{$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}