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-09-14 17:50:48 -04:00
|
|
|
impl<W: Writer> Writeable<W> for $st {
|
2018-09-16 13:50:42 -04:00
|
|
|
fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> {
|
2018-09-14 17:54:59 -04:00
|
|
|
w.size_hint($len);
|
|
|
|
$( self.$field.write(w)?; )*
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<R: Read> Readable<R> for $st {
|
|
|
|
fn read(r: &mut R) -> Result<Self, DecodeError> {
|
|
|
|
Ok(Self {
|
|
|
|
$($field: Readable::read(r)?),*
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
macro_rules! impl_writeable_len_match {
|
|
|
|
($st:ident, {$({$m: pat, $l: expr}),*}, {$($field:ident),*}) => {
|
|
|
|
impl<W: Writer> Writeable<W> for $st {
|
2018-09-16 13:50:42 -04:00
|
|
|
fn write(&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-09-14 17:50:48 -04:00
|
|
|
impl<R: Read> Readable<R> for $st {
|
|
|
|
fn read(r: &mut R) -> Result<Self, DecodeError> {
|
2018-09-14 16:43:47 -04:00
|
|
|
Ok(Self {
|
|
|
|
$($field: Readable::read(r)?),*
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|