Skip to content

Commit aabfdd5

Browse files
committed
Support LDK's new LengthReadable trait
Because we're always reading from a fixed-length buffer anyway, we can always support it with our existing code.
1 parent 691b15f commit aabfdd5

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

c-bindings-gen/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn maybe_convert_trait_impl<W: std::io::Write>(w: &mut W, trait_path: &syn::Path
108108
}
109109
writeln!(w, "}}").unwrap();
110110
},
111-
"lightning::util::ser::Readable"|"lightning::util::ser::ReadableArgs"|"lightning::util::ser::MaybeReadable" => {
111+
"lightning::util::ser::Readable"|"lightning::util::ser::LengthReadable"|"lightning::util::ser::ReadableArgs"|"lightning::util::ser::MaybeReadable" => {
112112
// Create the Result<Object, DecodeError> syn::Type
113113
let mut res_ty: syn::Type = parse_quote!(Result<#for_ty, lightning::ln::msgs::DecodeError>);
114114

c-bindings-gen/src/types.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
11601160
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
11611161
if !is_ref => Some("crate::c_types::ThirtyTwoBytes"),
11621162

1163-
"lightning::io::Read" => Some("crate::c_types::u8slice"),
1163+
"lightning::util::ser::LengthLimitedRead"|"lightning::io::Read" => Some("crate::c_types::u8slice"),
11641164

11651165
_ => None,
11661166
}
@@ -1287,7 +1287,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
12871287
"lightning::chain::ClaimId" if is_ref=> Some("&::lightning::chain::ClaimId( unsafe { *"),
12881288

12891289
// List of traits we map (possibly during processing of other files):
1290-
"lightning::io::Read" => Some("&mut "),
1290+
"lightning::util::ser::LengthLimitedRead"|"lightning::io::Read" => Some("&mut "),
12911291

12921292
_ => None,
12931293
}.map(|s| s.to_owned())
@@ -1399,7 +1399,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
13991399
if is_ref => Some(" })"),
14001400

14011401
// List of traits we map (possibly during processing of other files):
1402-
"lightning::io::Read" => Some(".to_reader()"),
1402+
"lightning::util::ser::LengthLimitedRead"|"lightning::io::Read" => Some(".to_slice()"),
14031403

14041404
_ => None,
14051405
}.map(|s| s.to_owned())
@@ -1530,7 +1530,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
15301530
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
15311531
if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
15321532

1533-
"lightning::io::Read" => Some("crate::c_types::u8slice::from_vec(&crate::c_types::reader_to_vec("),
1533+
"lightning::util::ser::LengthLimitedRead"|"lightning::io::Read" => Some("crate::c_types::u8slice::from_vec(&crate::c_types::reader_to_vec("),
15341534

15351535
_ => None,
15361536
}.map(|s| s.to_owned())
@@ -1640,7 +1640,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
16401640
|"lightning::sign::KeyMaterial"|"lightning::chain::ClaimId"
16411641
if !is_ref => Some(".0 }"),
16421642

1643-
"lightning::io::Read" => Some("))"),
1643+
"lightning::util::ser::LengthLimitedRead"|"lightning::io::Read" => Some("))"),
16441644

16451645
_ => None,
16461646
}.map(|s| s.to_owned())
@@ -1661,7 +1661,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
16611661
/// TODO: We should never need to use this!
16621662
fn real_rust_type_mapping<'equiv>(&self, thing: &'equiv str) -> &'equiv str {
16631663
match thing {
1664-
"lightning::io::Read" => "crate::c_types::io::Read",
1664+
"lightning::util::ser::LengthLimitedRead"|"lightning::io::Read" => "crate::c_types::io::Read",
16651665
_ => thing,
16661666
}
16671667
}

lightning-c-bindings/src/c_types/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,8 +880,8 @@ pub(crate) fn serialize_obj<I: lightning::util::ser::Writeable>(i: &I) -> derive
880880
i.write(&mut out).unwrap();
881881
derived::CVec_u8Z::from(out.0)
882882
}
883-
pub(crate) fn deserialize_obj<I: lightning::util::ser::Readable>(s: u8slice) -> Result<I, lightning::ln::msgs::DecodeError> {
884-
I::read(&mut s.to_slice())
883+
pub(crate) fn deserialize_obj<I: lightning::util::ser::LengthReadable>(s: u8slice) -> Result<I, lightning::ln::msgs::DecodeError> {
884+
I::read_from_fixed_length_buffer(&mut s.to_slice())
885885
}
886886
pub(crate) fn maybe_deserialize_obj<I: lightning::util::ser::MaybeReadable>(s: u8slice) -> Result<Option<I>, lightning::ln::msgs::DecodeError> {
887887
I::read(&mut s.to_slice())

0 commit comments

Comments
 (0)