+/// Equivalent to running [`_init_tlv_field_var`] then [`read_tlv_fields`].
+///
+/// If any unused values are read, their type MUST be specified or else `rustc` will read them as an
+/// `i64`.
+///
+/// This is exported for use by other exported macros, do not use directly.
+#[doc(hidden)]
+#[macro_export]
+macro_rules! _init_and_read_len_prefixed_tlv_fields {
+ ($reader: ident, {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}) => {
+ $(
+ $crate::_init_tlv_field_var!($field, $fieldty);
+ )*
+
+ $crate::read_tlv_fields!($reader, {
+ $(($type, $field, $fieldty)),*
+ });
+ }
+}
+
+/// Equivalent to running [`_init_tlv_field_var`] then [`decode_tlv_stream`].
+///
+/// If any unused values are read, their type MUST be specified or else `rustc` will read them as an
+/// `i64`.
+macro_rules! _init_and_read_tlv_stream {
+ ($reader: ident, {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}) => {
+ $(
+ $crate::_init_tlv_field_var!($field, $fieldty);
+ )*
+
+ $crate::decode_tlv_stream!($reader, {
+ $(($type, $field, $fieldty)),*
+ });
+ }
+}
+
+/// 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,
+/// ```
+/// # use lightning::impl_writeable_tlv_based;
+/// 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),
+/// });
+/// ```
+///
+/// [`Readable`]: crate::util::ser::Readable
+/// [`Writeable`]: crate::util::ser::Writeable
+#[macro_export]