X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Fser.rs;h=4e69a37d20e9fcc5e0d093804136ef9f90be1747;hb=2eb7db9ace08b57bfedbdac2b26961897b032e0b;hp=06578b9fba5b3d4e667dbe34c44038d3873a1212;hpb=b06a5afd5a07fcb5d446a38f8930ed3258f50c09;p=rust-lightning diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index 06578b9fb..4e69a37d2 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -260,6 +260,7 @@ impl<'a, T: Writeable> Writeable for VecWriteWrapper<'a, T> { Ok(()) } } + /// Wrapper to read elements from a given stream until it reaches the end of the stream. pub(crate) struct VecReadWrapper(pub Vec); impl Readable for VecReadWrapper { @@ -697,6 +698,18 @@ impl Readable for PaymentSecret { } } +impl Writeable for Box { + fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { + T::write(&**self, w) + } +} + +impl Readable for Box { + fn read(r: &mut R) -> Result { + Ok(Box::new(Readable::read(r)?)) + } +} + impl Writeable for Option { fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { match *self { @@ -823,3 +836,19 @@ impl Writeable for (A, B) { self.1.write(w) } } + +impl Readable for (A, B, C) { + fn read(r: &mut R) -> Result { + let a: A = Readable::read(r)?; + let b: B = Readable::read(r)?; + let c: C = Readable::read(r)?; + Ok((a, b, c)) + } +} +impl Writeable for (A, B, C) { + fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { + self.0.write(w)?; + self.1.write(w)?; + self.2.write(w) + } +}