Update auto-generated bindings
[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 a custom onion message.
20 #[repr(C)]
21 pub struct CustomOnionMessageContents {
22         /// An opaque pointer which is passed to your function implementations as an argument.
23         /// This has no meaning in the LDK, and can be NULL or any other value.
24         pub this_arg: *mut c_void,
25         /// Returns the TLV type identifying the message contents. MUST be >= 64.
26         #[must_use]
27         pub tlv_type: extern "C" fn (this_arg: *const c_void) -> u64,
28         /// Serialize the object into a byte array
29         pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
30         /// Frees any resources associated with this object given its this_arg pointer.
31         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
32         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
33 }
34 unsafe impl Send for CustomOnionMessageContents {}
35 unsafe impl Sync for CustomOnionMessageContents {}
36 #[no_mangle]
37 pub(crate) extern "C" fn CustomOnionMessageContents_clone_fields(orig: &CustomOnionMessageContents) -> CustomOnionMessageContents {
38         CustomOnionMessageContents {
39                 this_arg: orig.this_arg,
40                 tlv_type: Clone::clone(&orig.tlv_type),
41                 write: Clone::clone(&orig.write),
42                 free: Clone::clone(&orig.free),
43         }
44 }
45 impl lightning::util::ser::Writeable for CustomOnionMessageContents {
46         fn write<W: lightning::util::ser::Writer>(&self, w: &mut W) -> Result<(), crate::c_types::io::Error> {
47                 let vec = (self.write)(self.this_arg);
48                 w.write_all(vec.as_slice())
49         }
50 }
51
52 use lightning::onion_message::packet::CustomOnionMessageContents as rustCustomOnionMessageContents;
53 impl rustCustomOnionMessageContents for CustomOnionMessageContents {
54         fn tlv_type(&self) -> u64 {
55                 let mut ret = (self.tlv_type)(self.this_arg);
56                 ret
57         }
58 }
59
60 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
61 // directly as a Deref trait in higher-level structs:
62 impl core::ops::Deref for CustomOnionMessageContents {
63         type Target = Self;
64         fn deref(&self) -> &Self {
65                 self
66         }
67 }
68 /// Calls the free function if one is set
69 #[no_mangle]
70 pub extern "C" fn CustomOnionMessageContents_free(this_ptr: CustomOnionMessageContents) { }
71 impl Drop for CustomOnionMessageContents {
72         fn drop(&mut self) {
73                 if let Some(f) = self.free {
74                         f(self.this_arg);
75                 }
76         }
77 }