}
}
+impl<T: Writeable> Writeable for Box<T> {
+ fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
+ T::write(&**self, w)
+ }
+}
+
+impl<T: Readable> Readable for Box<T> {
+ fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+ Ok(Box::new(Readable::read(r)?))
+ }
+}
+
impl<T: Writeable> Writeable for Option<T> {
fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
match *self {
self.1.write(w)
}
}
+
+impl<A: Readable, B: Readable, C: Readable> Readable for (A, B, C) {
+ fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+ let a: A = Readable::read(r)?;
+ let b: B = Readable::read(r)?;
+ let c: C = Readable::read(r)?;
+ Ok((a, b, c))
+ }
+}
+impl<A: Writeable, B: Writeable, C: Writeable> Writeable for (A, B, C) {
+ fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
+ self.0.write(w)?;
+ self.1.write(w)?;
+ self.2.write(w)
+ }
+}
#[cfg(test)]
mod tests {
use prelude::*;
- use std::io::{Cursor, Read};
+ use std::io::Cursor;
use ln::msgs::DecodeError;
use util::ser::{Readable, Writeable, HighZeroBytesDroppedVarInt, VecWriter};
use bitcoin::secp256k1::PublicKey;
(0xdeadbeef1badbeef, 0x1bad1dea, Some(0x01020304)));
}
- impl Readable for (PublicKey, u64, u64) {
- #[inline]
- fn read<R: Read>(reader: &mut R) -> Result<(PublicKey, u64, u64), DecodeError> {
- Ok((Readable::read(reader)?, Readable::read(reader)?, Readable::read(reader)?))
- }
- }
-
// BOLT TLV test cases
fn tlv_reader_n1(s: &[u8]) -> Result<(Option<HighZeroBytesDroppedVarInt<u64>>, Option<u64>, Option<(PublicKey, u64, u64)>, Option<u16>), DecodeError> {
let mut s = Cursor::new(s);