Macro impl_writeable_tlv_based_enum
macro_rules! impl_writeable_tlv_based_enum {
($st: ident,
$(($variant_id: expr, $variant_name: ident) =>
{$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}
),*
$($(,)? {$tuple_variant_id: expr, $tuple_variant_name: ident} => ()),*
$(,)?
) => { ... };
}
Expand description
Implement Readable
and Writeable
for an enum, with struct variants stored as TLVs and tuple
variants stored directly.
The format is, for example,
enum EnumName {
StructVariantA {
required_variant_field: u64,
optional_variant_field: Option<u8>,
},
StructVariantB {
variant_field_a: bool,
variant_field_b: u32,
variant_vec_field: Vec<u32>,
},
TupleVariantA(),
TupleVariantB(Vec<u8>),
}
impl_writeable_tlv_based_enum!(EnumName,
(0, StructVariantA) => {(0, required_variant_field, required), (1, optional_variant_field, option)},
(1, StructVariantB) => {(0, variant_field_a, required), (1, variant_field_b, required), (2, variant_vec_field, optional_vec)},
(2, TupleVariantA) => {}, // Note that empty tuple variants have to use the struct syntax due to rust limitations
{3, TupleVariantB} => (),
);
The type is written as a single byte, followed by length-prefixed variant data.
Attempts to read an unknown type byte result in DecodeError::UnknownRequiredFeature
.
Note that the serialization for tuple variants (as well as the call format) was changed in LDK 0.0.124.