13
13
//! [`Readable`]: crate::util::ser::Readable
14
14
//! [`Writeable`]: crate::util::ser::Writeable
15
15
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
-
31
16
/// Implements serialization for a single TLV record.
32
17
/// This is exported for use by other exported macros, do not use directly.
33
18
#[ doc( hidden) ]
@@ -944,16 +929,23 @@ macro_rules! _decode_and_build {
944
929
} }
945
930
}
946
931
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
+ ///
948
936
/// If `$fieldty` is `required`, then `$field` is a required field that is not an [`Option`] nor a [`Vec`].
949
937
/// 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`.
950
939
/// 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.
951
943
/// If `$fieldty` is `optional_vec`, then `$field` is a [`Vec`], which needs to have its individual elements serialized.
952
944
/// Note that for `optional_vec` no bytes are written if the vec is empty
953
945
/// If `$fieldty` is `(legacy, $ty, $write)` then, when writing, the function $write will be
954
946
/// called with the object being serialized and a returned `Option` and is written as a TLV if
955
947
/// `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 ).
957
949
///
958
950
/// For example,
959
951
/// ```
@@ -963,17 +955,21 @@ macro_rules! _decode_and_build {
963
955
/// tlv_default_integer: u32,
964
956
/// tlv_optional_integer: Option<u32>,
965
957
/// tlv_vec_type_integer: Vec<u32>,
958
+ /// tlv_upgraded_integer: u32,
966
959
/// }
967
960
///
968
961
/// impl_writeable_tlv_based!(LightningMessage, {
969
962
/// (0, tlv_integer, required),
970
963
/// (1, tlv_default_integer, (default_value, 7)),
971
964
/// (2, tlv_optional_integer, option),
972
965
/// (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))
973
968
/// });
974
969
/// ```
975
970
///
976
971
/// [`Readable`]: crate::util::ser::Readable
972
+ /// [`MaybeReadable`]: crate::util::ser::MaybeReadable
977
973
/// [`Writeable`]: crate::util::ser::Writeable
978
974
/// [`Vec`]: crate::prelude::Vec
979
975
#[ macro_export]
0 commit comments