Skip to content

Commit a40e32b

Browse files
ser: Add MaybeReadableArgs trait
Useful in decoding a custom message, so (a) the message type can be provided to the handler and (b) None can be returned if the message type is unknown. Used in upcoming commit(s) to support custom onion messages.
1 parent a031ff9 commit a40e32b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lightning/src/util/ser.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,15 @@ impl<T: Readable> MaybeReadable for T {
269269
}
270270
}
271271

272+
/// A trait that various rust-lightning types implement allowing them to (maybe) be read in from a
273+
/// Read, given some additional set of arguments which is required to deserialize.
274+
///
275+
/// (C-not exported) as we only export serialization to/from byte arrays instead
276+
pub trait MaybeReadableArgs<P> {
277+
/// Reads a Self in from the given Read
278+
fn read<R: Read>(reader: &mut R, params: P) -> Result<Option<Self>, DecodeError> where Self: Sized;
279+
}
280+
272281
pub(crate) struct OptionDeserWrapper<T: Readable>(pub Option<T>);
273282
impl<T: Readable> Readable for OptionDeserWrapper<T> {
274283
#[inline]

0 commit comments

Comments
 (0)