Update auto-generated bindings to 0.0.113
[ldk-c-bindings] / lightning-c-bindings / src / lightning / onion_message / packet.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
8
9 //! Structs and enums useful for constructing and reading an onion message packet.
10
11 use alloc::str::FromStr;
12 use core::ffi::c_void;
13 use core::convert::Infallible;
14 use bitcoin::hashes::Hash;
15 use crate::c_types::*;
16 #[cfg(feature="no-std")]
17 use alloc::{vec::Vec, boxed::Box};
18
19 /// The contents of an onion message. In the context of offers, this would be the invoice, invoice
20 /// request, or invoice error.
21 #[must_use]
22 #[repr(C)]
23 pub enum OnionMessageContents {
24         /// A custom onion message specified by the user.
25         Custom(
26                 crate::lightning::onion_message::packet::CustomOnionMessageContents),
27 }
28 use lightning::onion_message::packet::OnionMessageContents as OnionMessageContentsImport;
29 pub(crate) type nativeOnionMessageContents = OnionMessageContentsImport<crate::lightning::onion_message::packet::CustomOnionMessageContents>;
30
31 impl OnionMessageContents {
32         #[allow(unused)]
33         pub(crate) fn into_native(self) -> nativeOnionMessageContents {
34                 match self {
35                         OnionMessageContents::Custom (mut a, ) => {
36                                 nativeOnionMessageContents::Custom (
37                                         a,
38                                 )
39                         },
40                 }
41         }
42         #[allow(unused)]
43         pub(crate) fn native_into(native: nativeOnionMessageContents) -> Self {
44                 match native {
45                         nativeOnionMessageContents::Custom (mut a, ) => {
46                                 OnionMessageContents::Custom (
47                                         Into::into(a),
48                                 )
49                         },
50                 }
51         }
52 }
53 /// Frees any resources used by the OnionMessageContents
54 #[no_mangle]
55 pub extern "C" fn OnionMessageContents_free(this_ptr: OnionMessageContents) { }
56 #[no_mangle]
57 /// Utility method to constructs a new Custom-variant OnionMessageContents
58 pub extern "C" fn OnionMessageContents_custom(a: crate::lightning::onion_message::packet::CustomOnionMessageContents) -> OnionMessageContents {
59         OnionMessageContents::Custom(a, )
60 }
61 /// The contents of a custom onion message.
62 #[repr(C)]
63 pub struct CustomOnionMessageContents {
64         /// An opaque pointer which is passed to your function implementations as an argument.
65         /// This has no meaning in the LDK, and can be NULL or any other value.
66         pub this_arg: *mut c_void,
67         /// Returns the TLV type identifying the message contents. MUST be >= 64.
68         #[must_use]
69         pub tlv_type: extern "C" fn (this_arg: *const c_void) -> u64,
70         /// Serialize the object into a byte array
71         pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
72         /// Frees any resources associated with this object given its this_arg pointer.
73         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
74         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
75 }
76 unsafe impl Send for CustomOnionMessageContents {}
77 unsafe impl Sync for CustomOnionMessageContents {}
78 #[no_mangle]
79 pub(crate) extern "C" fn CustomOnionMessageContents_clone_fields(orig: &CustomOnionMessageContents) -> CustomOnionMessageContents {
80         CustomOnionMessageContents {
81                 this_arg: orig.this_arg,
82                 tlv_type: Clone::clone(&orig.tlv_type),
83                 write: Clone::clone(&orig.write),
84                 free: Clone::clone(&orig.free),
85         }
86 }
87 impl lightning::util::ser::Writeable for CustomOnionMessageContents {
88         fn write<W: lightning::util::ser::Writer>(&self, w: &mut W) -> Result<(), crate::c_types::io::Error> {
89                 let vec = (self.write)(self.this_arg);
90                 w.write_all(vec.as_slice())
91         }
92 }
93
94 use lightning::onion_message::packet::CustomOnionMessageContents as rustCustomOnionMessageContents;
95 impl rustCustomOnionMessageContents for CustomOnionMessageContents {
96         fn tlv_type(&self) -> u64 {
97                 let mut ret = (self.tlv_type)(self.this_arg);
98                 ret
99         }
100 }
101
102 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
103 // directly as a Deref trait in higher-level structs:
104 impl core::ops::Deref for CustomOnionMessageContents {
105         type Target = Self;
106         fn deref(&self) -> &Self {
107                 self
108         }
109 }
110 /// Calls the free function if one is set
111 #[no_mangle]
112 pub extern "C" fn CustomOnionMessageContents_free(this_ptr: CustomOnionMessageContents) { }
113 impl Drop for CustomOnionMessageContents {
114         fn drop(&mut self) {
115                 if let Some(f) = self.free {
116                         f(self.this_arg);
117                 }
118         }
119 }