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
ⓘ
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), (3, TupleVariantB),
);
The type is written as a single byte, followed by any variant data.
Attempts to read an unknown type byte result in DecodeError::UnknownRequiredFeature
.