+/// The contents of an [`OnionMessage`] as read from the wire.
+///
+/// [`OnionMessage`]: crate::ln::msgs::OnionMessage
+#[derive(Debug)]
+pub enum ParsedOnionMessageContents<T: OnionMessageContents> {
+ /// A message related to BOLT 12 Offers.
+ Offers(OffersMessage),
+ /// A custom onion message specified by the user.
+ Custom(T),
+}
+
+impl<T: OnionMessageContents> OnionMessageContents for ParsedOnionMessageContents<T> {
+ /// Returns the type that was used to decode the message payload.
+ ///
+ /// This is not exported to bindings users as methods on non-cloneable enums are not currently exportable
+ fn tlv_type(&self) -> u64 {
+ match self {
+ &ParsedOnionMessageContents::Offers(ref msg) => msg.tlv_type(),
+ &ParsedOnionMessageContents::Custom(ref msg) => msg.tlv_type(),
+ }
+ }
+}
+
+impl<T: OnionMessageContents> Writeable for ParsedOnionMessageContents<T> {
+ fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
+ match self {
+ ParsedOnionMessageContents::Offers(msg) => Ok(msg.write(w)?),
+ ParsedOnionMessageContents::Custom(msg) => Ok(msg.write(w)?),
+ }
+ }
+}
+
+/// The contents of an onion message.
+pub trait OnionMessageContents: Writeable + core::fmt::Debug {
+ /// Returns the TLV type identifying the message contents. MUST be >= 64.
+ fn tlv_type(&self) -> u64;
+}