2018-09-14 16:43:47 -04:00
|
|
|
macro_rules! impl_writeable {
|
2018-09-14 17:54:59 -04:00
|
|
|
($st:ident, $len: expr, {$($field:ident),*}) => {
|
2018-10-26 14:35:50 -04:00
|
|
|
impl ::util::ser::Writeable for $st {
|
|
|
|
fn write<W: ::util::ser::Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
|
2018-10-18 14:58:56 -04:00
|
|
|
if $len != 0 {
|
|
|
|
w.size_hint($len);
|
|
|
|
}
|
2018-09-14 17:54:59 -04:00
|
|
|
$( self.$field.write(w)?; )*
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 14:35:50 -04:00
|
|
|
impl<R: ::std::io::Read> ::util::ser::Readable<R> for $st {
|
|
|
|
fn read(r: &mut R) -> Result<Self, ::ln::msgs::DecodeError> {
|
2018-09-14 17:54:59 -04:00
|
|
|
Ok(Self {
|
2018-10-26 14:35:50 -04:00
|
|
|
$($field: ::util::ser::Readable::read(r)?),*
|
2018-09-14 17:54:59 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
macro_rules! impl_writeable_len_match {
|
|
|
|
($st:ident, {$({$m: pat, $l: expr}),*}, {$($field:ident),*}) => {
|
2018-09-16 14:02:58 -04:00
|
|
|
impl Writeable for $st {
|
|
|
|
fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
|
2018-09-14 17:54:59 -04:00
|
|
|
w.size_hint(match *self {
|
|
|
|
$($m => $l,)*
|
|
|
|
});
|
2018-09-14 16:43:47 -04:00
|
|
|
$( self.$field.write(w)?; )*
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-18 14:58:56 -04:00
|
|
|
impl<R: ::std::io::Read> Readable<R> for $st {
|
2018-09-14 17:50:48 -04:00
|
|
|
fn read(r: &mut R) -> Result<Self, DecodeError> {
|
2018-09-14 16:43:47 -04:00
|
|
|
Ok(Self {
|
|
|
|
$($field: Readable::read(r)?),*
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|