//! Utilities for strings.
use alloc::str::FromStr;
+use alloc::string::String;
use core::ffi::c_void;
use core::convert::Infallible;
use bitcoin::hashes::Hash;
#[allow(unused)]
/// Used only if an object of this type is returned as a trait impl by a method
pub(crate) extern "C" fn UntrustedString_clone_void(this_ptr: *const c_void) -> *mut c_void {
- Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUntrustedString)).clone() })) as *mut c_void
+ Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUntrustedString)).clone() })) as *mut c_void
}
#[no_mangle]
/// Creates a copy of the UntrustedString
pub extern "C" fn UntrustedString_clone(orig: &UntrustedString) -> UntrustedString {
orig.clone()
}
+/// Get a string which allows debug introspection of a UntrustedString object
+pub extern "C" fn UntrustedString_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning::util::string::UntrustedString }).into()}
/// Checks if two UntrustedStrings contain equal inner contents.
/// This ignores pointers and is_owned flags and looks at the values in fields.
/// Two objects with NULL inner values will be considered "equal" here.
if a.inner.is_null() || b.inner.is_null() { return false; }
if a.get_native_ref() == b.get_native_ref() { true } else { false }
}
+/// Generates a non-cryptographic 64-bit hash of the UntrustedString.
+#[no_mangle]
+pub extern "C" fn UntrustedString_hash(o: &UntrustedString) -> u64 {
+ if o.inner.is_null() { return 0; }
+ // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
+ #[allow(deprecated)]
+ let mut hasher = core::hash::SipHasher::new();
+ core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
+ core::hash::Hasher::finish(&hasher)
+}
#[no_mangle]
/// Serialize the UntrustedString object into a byte array which can be read by UntrustedString_read
pub extern "C" fn UntrustedString_write(obj: &crate::lightning::util::string::UntrustedString) -> crate::c_types::derived::CVec_u8Z {
crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
}
-#[no_mangle]
+#[allow(unused)]
pub(crate) extern "C" fn UntrustedString_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUntrustedString) })
}
let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::util::string::UntrustedString { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
local_res
}
+#[no_mangle]
+/// Get the string representation of a UntrustedString object
+pub extern "C" fn UntrustedString_to_str(o: &crate::lightning::util::string::UntrustedString) -> Str {
+ alloc::format!("{}", o.get_native_ref()).into()
+}
use lightning::util::string::PrintableString as nativePrintableStringImport;
-pub(crate) type nativePrintableString = nativePrintableStringImport<'static>;
+pub(crate) type nativePrintableString = nativePrintableStringImport<'static, >;
/// A string that displays only printable characters, replacing control characters with
/// [`core::char::REPLACEMENT_CHARACTER`].
a_arg.into_str(),
)), is_owned: true }
}
+/// Get a string which allows debug introspection of a PrintableString object
+pub extern "C" fn PrintableString_debug_str_void(o: *const c_void) -> Str {
+ alloc::format!("{:?}", unsafe { o as *const crate::lightning::util::string::PrintableString }).into()}
+#[no_mangle]
+/// Get the string representation of a PrintableString object
+pub extern "C" fn PrintableString_to_str(o: &crate::lightning::util::string::PrintableString) -> Str {
+ alloc::format!("{}", o.get_native_ref()).into()
+}