I see that we should implement Readable
and Writable
for wire messages (+ different issues) at rust-lightning/lightning/src/ln/msgs.rs#L3673-L3698.
However I didn’t get the distinction between (utilizing present WarningMessage
as instance):
impl Writeable for WarningMessage {
fn write(&self, w: &mut W) -> End result<(), io::Error> {
self.channel_id.write(w)?;
(self.information.len() as u16).write(w)?;
w.write_all(self.information.as_bytes())?;
Okay(())
}
}
impl Readable for WarningMessage {
fn learn(r: &mut R) -> End result {
Okay(Self {
channel_id: Readable::learn(r)?,
information: {
let sz: usize = ::learn(r)? as usize;
let mut information = Vec::with_capacity(sz);
information.resize(sz, 0);
r.read_exact(&mut information)?;
match String::from_utf8(information) {
Okay(s) => s,
Err(_) => return Err(DecodeError::InvalidValue),
}
}
})
}
}
And:
impl_writeable_msg!(WarningMessage, {
channel_id,
information,
}, {});
Each passes the check:
cargo check --package lightning --lib -- ln::msgs::exams::encoding_warning --exact --show-output
I see that we should implement Readable
and Writable
for wire messages (+ different issues) at rust-lightning/lightning/src/ln/msgs.rs#L3673-L3698.
However I didn’t get the distinction between (utilizing present WarningMessage
as instance):
impl Writeable for WarningMessage {
fn write(&self, w: &mut W) -> End result<(), io::Error> {
self.channel_id.write(w)?;
(self.information.len() as u16).write(w)?;
w.write_all(self.information.as_bytes())?;
Okay(())
}
}
impl Readable for WarningMessage {
fn learn(r: &mut R) -> End result {
Okay(Self {
channel_id: Readable::learn(r)?,
information: {
let sz: usize = ::learn(r)? as usize;
let mut information = Vec::with_capacity(sz);
information.resize(sz, 0);
r.read_exact(&mut information)?;
match String::from_utf8(information) {
Okay(s) => s,
Err(_) => return Err(DecodeError::InvalidValue),
}
}
})
}
}
And:
impl_writeable_msg!(WarningMessage, {
channel_id,
information,
}, {});
Each passes the check:
cargo check --package lightning --lib -- ln::msgs::exams::encoding_warning --exact --show-output