X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Fser.rs;h=ecf85839a5a8e19ebfed3f8e87b8b5832427e4a5;hb=28c9b56113ff1ebb1b505a2c979c55c1626aa06b;hp=d26be4c9ef7a354873cd8c431419b5f1e72bc9e7;hpb=daeb5a62914fef04d9d51e8d30ced9d6c1103b42;p=rust-lightning
diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs
index d26be4c9..ecf85839 100644
--- a/lightning/src/util/ser.rs
+++ b/lightning/src/util/ser.rs
@@ -244,6 +244,14 @@ pub(crate) trait LengthReadableArgs
where Self: Sized
fn read(reader: &mut R, params: P) -> Result;
}
+/// A trait that various higher-level rust-lightning types implement allowing them to be read in
+/// from a Read, requiring the implementer to provide the total length of the read.
+pub(crate) trait LengthReadable where Self: Sized
+{
+ /// Reads a Self in from the given LengthRead
+ fn read(reader: &mut R) -> Result;
+}
+
/// A trait that various rust-lightning types implement allowing them to (maybe) be read in from a Read
///
/// (C-not exported) as we only export serialization to/from byte arrays instead
@@ -268,6 +276,12 @@ impl Readable for OptionDeserWrapper {
Ok(Self(Some(Readable::read(reader)?)))
}
}
+/// When handling default_values, we want to map the default-value T directly
+/// to a OptionDeserWrapper in a way that works for `field: T = t;` as
+/// well. Thus, we assume `Into for T` does nothing and use that.
+impl From for OptionDeserWrapper {
+ fn from(t: T) -> OptionDeserWrapper { OptionDeserWrapper(Some(t)) }
+}
/// Wrapper to write each element of a Vec with no length prefix
pub(crate) struct VecWriteWrapper<'a, T: Writeable>(pub &'a Vec);