+#[derive(Debug)]
+/// The contents of an onion message. In the context of offers, this would be the invoice, invoice
+/// request, or invoice error.
+pub enum OnionMessageContents<T: CustomOnionMessageContents> {
+ /// A message related to BOLT 12 Offers.
+ Offers(OffersMessage),
+ /// A custom onion message specified by the user.
+ Custom(T),
+}
+
+impl<T: CustomOnionMessageContents> OnionMessageContents<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
+ pub fn tlv_type(&self) -> u64 {
+ match self {
+ &OnionMessageContents::Offers(ref msg) => msg.tlv_type(),
+ &OnionMessageContents::Custom(ref msg) => msg.tlv_type(),
+ }
+ }
+}
+
+/// This is not exported to bindings users as methods on non-cloneable enums are not currently exportable
+impl<T: CustomOnionMessageContents> Writeable for OnionMessageContents<T> {
+ fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
+ match self {
+ OnionMessageContents::Offers(msg) => Ok(msg.write(w)?),
+ OnionMessageContents::Custom(msg) => Ok(msg.write(w)?),
+ }
+ }
+}
+
+/// The contents of a custom onion message.
+pub trait CustomOnionMessageContents: Writeable {
+ /// Returns the TLV type identifying the message contents. MUST be >= 64.
+ fn tlv_type(&self) -> u64;
+}