Skip to content

Commit

Permalink
docs: add a usage example for impl_writeable_tlv_based
Browse files Browse the repository at this point in the history
  • Loading branch information
mariocynicys committed Jan 8, 2023
1 parent 18ea6a2 commit 266a95d
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions lightning/src/util/ser_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,8 @@ macro_rules! write_ver_prefix {
}
}

/// Writes out a suffix to an object which contains potentially backwards-compatible, optional
/// fields which old nodes can happily ignore.
/// Writes out a suffix to an object as a length-prefixed TLV stream which contains potentially
/// backwards-compatible, optional fields which old nodes can happily ignore.
///
/// It is written out in TLV format and, as with all TLV fields, unknown even fields cause a
/// [`DecodeError::UnknownRequiredFeature`] error, with unknown odd fields ignored.
Expand Down Expand Up @@ -627,10 +627,28 @@ macro_rules! _init_and_read_tlv_fields {
}

/// 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.
/// 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
Expand Down

0 comments on commit 266a95d

Please sign in to comment.