ser: Add MaybeReadableArgs trait
authorValentine Wallace <vwallace@protonmail.com>
Mon, 17 Oct 2022 20:05:32 +0000 (16:05 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Mon, 17 Oct 2022 20:05:36 +0000 (16:05 -0400)
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.

lightning/src/util/ser.rs

index 852aa8f15892e5bbc3d14dd265ecf7f168044653..6b17ec7ed6b10344f69028001e028d69b6cc99d4 100644 (file)
@@ -269,6 +269,15 @@ impl<T: Readable> MaybeReadable for T {
        }
 }
 
+/// A trait that various rust-lightning types implement allowing them to (maybe) be read in from a
+/// Read, given some additional set of arguments which is required to deserialize.
+///
+/// (C-not exported) as we only export serialization to/from byte arrays instead
+pub trait MaybeReadableArgs<P> {
+       /// Reads a Self in from the given Read
+       fn read<R: Read>(reader: &mut R, params: P) -> Result<Option<Self>, DecodeError> where Self: Sized;
+}
+
 pub(crate) struct OptionDeserWrapper<T: Readable>(pub Option<T>);
 impl<T: Readable> Readable for OptionDeserWrapper<T> {
        #[inline]