1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
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.
9 //! A very simple serialization framework which is used to serialize/deserialize messages as well
10 //! as ChannelsManagers and ChannelMonitors.
12 use alloc::str::FromStr;
13 use core::ffi::c_void;
14 use core::convert::Infallible;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17 #[cfg(feature="no-std")]
18 use alloc::{vec::Vec, boxed::Box};
20 /// serialization buffer size
23 pub static MAX_BUF_SIZE: usize = lightning::util::ser::MAX_BUF_SIZE;
25 use lightning::util::ser::BigSize as nativeBigSizeImport;
26 pub(crate) type nativeBigSize = nativeBigSizeImport;
28 /// Lightning TLV uses a custom variable-length integer called BigSize. It is similar to Bitcoin's
29 /// variable-length integers except that it is serialized in big-endian instead of little-endian.
31 /// Like Bitcoin's variable-length integer, it exhibits ambiguity in that certain values can be
32 /// encoded in several different ways, which we must check for at deserialization-time. Thus, if
33 /// you're looking for an example of a variable-length integer to use for your own project, move
34 /// along, this is a rather poor design.
38 /// A pointer to the opaque Rust object.
40 /// Nearly everywhere, inner must be non-null, however in places where
41 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
42 pub inner: *mut nativeBigSize,
43 /// Indicates that this is the only struct which contains the same pointer.
45 /// Rust functions which take ownership of an object provided via an argument require
46 /// this to be true and invalidate the object pointed to by inner.
50 impl Drop for BigSize {
52 if self.is_owned && !<*mut nativeBigSize>::is_null(self.inner) {
53 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
57 /// Frees any resources used by the BigSize, if is_owned is set and inner is non-NULL.
59 pub extern "C" fn BigSize_free(this_obj: BigSize) { }
61 /// Used only if an object of this type is returned as a trait impl by a method
62 pub(crate) extern "C" fn BigSize_free_void(this_ptr: *mut c_void) {
63 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeBigSize); }
67 pub(crate) fn get_native_ref(&self) -> &'static nativeBigSize {
68 unsafe { &*ObjOps::untweak_ptr(self.inner) }
70 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeBigSize {
71 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
73 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
74 pub(crate) fn take_inner(mut self) -> *mut nativeBigSize {
75 assert!(self.is_owned);
76 let ret = ObjOps::untweak_ptr(self.inner);
77 self.inner = core::ptr::null_mut();
82 pub extern "C" fn BigSize_get_a(this_ptr: &BigSize) -> u64 {
83 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
87 pub extern "C" fn BigSize_set_a(this_ptr: &mut BigSize, mut val: u64) {
88 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val;
90 /// Constructs a new BigSize given each field
93 pub extern "C" fn BigSize_new(mut a_arg: u64) -> BigSize {
94 BigSize { inner: ObjOps::heap_alloc(lightning::util::ser::BigSize (