macro_rules! impl_writeable_tlv_based { ($st: ident, {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}) => { ... }; }
Expand description
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.
If $fieldty
is option
, then $field
is optional field.
If $fieldty
is optional_vec
, then $field
is a Vec
, which needs to have its individual elements serialized.
Note that for optional_vec
no bytes are written if the vec is empty
For example,
struct LightningMessage {
tlv_integer: u32,
tlv_default_integer: u32,
tlv_optional_integer: Option<u32>,
tlv_vec_type_integer: Vec<u32>,
}
impl_writeable_tlv_based!(LightningMessage, {
(0, tlv_integer, required),
(1, tlv_default_integer, (default_value, 7)),
(2, tlv_optional_integer, option),
(3, tlv_vec_type_integer, optional_vec),
});