-/// 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 `option`, then $field is optional field.
-/// if $fieldty is `vec_type`, then $field is a Vec, which needs to have its individual elements
-/// serialized.
+/// Equivalent to running [`_init_tlv_field_var`] then [`read_tlv_fields`].
+///
+/// This is exported for use by other exported macros, do not use directly.
+#[doc(hidden)]
+#[macro_export]
+macro_rules! _init_and_read_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)),*
+ });
+ }
+}
+
+/// 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 `vec_type`, then `$field` is a [`Vec`], which needs to have its individual elements serialized.
+///
+/// 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, vec_type),
+/// });
+/// ```
+///
+/// [`Readable`]: crate::util::ser::Readable
+/// [`Writeable`]: crate::util::ser::Writeable
+#[macro_export]