1313//! [`Readable`]: crate::util::ser::Readable
1414//! [`Writeable`]: crate::util::ser::Writeable
1515
16- // There are quite a few TLV serialization "types" which behave differently. We currently only
17- // publicly document the `optional` and `required` types, not supporting anything else publicly and
18- // changing them at will.
19- //
20- // Some of the other types include:
21- // * (default_value, $default) - reads optionally, reading $default if no TLV is present
22- // * (static_value, $value) - ignores any TLVs, always using $value
23- // * required_vec - reads into a Vec without a length prefix, failing if no TLV is present.
24- // * optional_vec - reads into an Option<Vec> without a length prefix, continuing if no TLV is
25- // present. Writes from a Vec directly, only if any elements are present. Note
26- // that the struct deserialization macros return a Vec, not an Option.
27- // * upgradable_option - reads via MaybeReadable.
28- // * upgradable_required - reads via MaybeReadable, requiring a TLV be present but may return None
29- // if MaybeReadable::read() returns None.
30-
3116/// Implements serialization for a single TLV record.
3217/// This is exported for use by other exported macros, do not use directly.
3318#[ doc( hidden) ]
@@ -944,16 +929,23 @@ macro_rules! _decode_and_build {
944929 } }
945930}
946931
947- /// Implements [`Readable`]/[`Writeable`] for a struct storing it as a set of TLVs
932+ /// Implements [`Readable`]/[`Writeable`] for a struct storing it as a set of TLVs. Each TLV is
933+ /// read/written in the order they appear and contains a type number, a field name, and a
934+ /// de/serialization method, from the following:
935+ ///
948936/// If `$fieldty` is `required`, then `$field` is a required field that is not an [`Option`] nor a [`Vec`].
949937/// If `$fieldty` is `(default_value, $default)`, then `$field` will be set to `$default` if not present.
938+ /// If `$fieldty` is `(static_value, $static)`, then `$field` will be set to `$static`.
950939/// If `$fieldty` is `option`, then `$field` is optional field.
940+ /// If `$fieldty` is `upgradable_option`, then `$field` is optional and read via [`MaybeReadable`].
941+ /// If `$fieldty` is `upgradable_required`, then `$field` is stored as an [`Option`] and read via
942+ /// [`MaybeReadable`], requiring the TLV to be present.
951943/// If `$fieldty` is `optional_vec`, then `$field` is a [`Vec`], which needs to have its individual elements serialized.
952944/// Note that for `optional_vec` no bytes are written if the vec is empty
953945/// If `$fieldty` is `(legacy, $ty, $write)` then, when writing, the function $write will be
954946/// called with the object being serialized and a returned `Option` and is written as a TLV if
955947/// `Some`. When reading, an optional field of type `$ty` is read (which can be used in later
956- /// `default_value` or `static_value` fields).
948+ /// `default_value` or `static_value` fields by referring to the value by name ).
957949///
958950/// For example,
959951/// ```
@@ -963,17 +955,21 @@ macro_rules! _decode_and_build {
963955/// tlv_default_integer: u32,
964956/// tlv_optional_integer: Option<u32>,
965957/// tlv_vec_type_integer: Vec<u32>,
958+ /// tlv_upgraded_integer: u32,
966959/// }
967960///
968961/// impl_writeable_tlv_based!(LightningMessage, {
969962/// (0, tlv_integer, required),
970963/// (1, tlv_default_integer, (default_value, 7)),
971964/// (2, tlv_optional_integer, option),
972965/// (3, tlv_vec_type_integer, optional_vec),
966+ /// (4, unwritten_type, (legacy, u32, |us: &LightningMessage| Some(us.tlv_integer))),
967+ /// (_unused, tlv_upgraded_integer, (static_value, unwritten_type.unwrap_or(0) * 2))
973968/// });
974969/// ```
975970///
976971/// [`Readable`]: crate::util::ser::Readable
972+ /// [`MaybeReadable`]: crate::util::ser::MaybeReadable
977973/// [`Writeable`]: crate::util::ser::Writeable
978974/// [`Vec`]: crate::prelude::Vec
979975#[ macro_export]
0 commit comments