♻️ refactor: fix some unused code warnings

main
_ 2021-12-09 00:03:56 +00:00
parent 50bfd422f9
commit dbedc6083e
2 changed files with 8 additions and 10 deletions

View File

@ -19,10 +19,10 @@ pub enum Message {
// 1 // 1
Request1 { Request1 {
idem_id: [u8; 8], idem_id: [u8; 8],
mac: Option <[u8; 6]> mac: Option <Mac>
}, },
// 2 // 2
Response1 (Option <[u8; 6]>), Response1 (Option <Mac>),
// 3 // 3
Response2 (Response2), Response2 (Response2),
} }
@ -66,7 +66,7 @@ impl Write for DummyWriter {
} }
impl Message { impl Message {
pub fn write <T> (&self, w: &mut Cursor <T>) -> Result <(), std::io::Error> pub fn write <T> (&self, w: &mut Cursor <T>) -> Result <(), MessageError>
where Cursor <T>: Write where Cursor <T>: Write
{ {
match self { match self {
@ -102,13 +102,11 @@ impl Message {
} }
fn write_response_2 <W: Write> (w: &mut W, params: &Response2) fn write_response_2 <W: Write> (w: &mut W, params: &Response2)
-> Result <(), std::io::Error> -> Result <(), MessageError>
{ {
w.write_all (&params.idem_id)?; w.write_all (&params.idem_id)?;
let nickname = params.nickname.as_bytes (); let nickname = params.nickname.as_bytes ();
let nickname_len = u32::try_from (nickname.len ()).unwrap (); tlv::Writer::<_>::lv_bytes (w, nickname)?;
w.write_all (&nickname_len.to_le_bytes ())?;
w.write_all (&nickname)?;
Ok (()) Ok (())
} }
@ -124,14 +122,14 @@ impl Message {
Ok (()) Ok (())
} }
pub fn to_vec (&self) -> Result <Vec <u8>, tlv::TlvError> { pub fn to_vec (&self) -> Result <Vec <u8>, MessageError> {
let mut cursor = Cursor::new (Vec::with_capacity (PACKET_SIZE)); let mut cursor = Cursor::new (Vec::with_capacity (PACKET_SIZE));
cursor.write_all (&MAGIC_NUMBER)?; cursor.write_all (&MAGIC_NUMBER)?;
self.write (&mut cursor)?; self.write (&mut cursor)?;
Ok (cursor.into_inner ()) Ok (cursor.into_inner ())
} }
pub fn many_to_vec (msgs: &[Self]) -> Result <Vec <u8>, tlv::TlvError> { pub fn many_to_vec (msgs: &[Self]) -> Result <Vec <u8>, MessageError> {
let mut cursor = Cursor::new (Vec::with_capacity (PACKET_SIZE)); let mut cursor = Cursor::new (Vec::with_capacity (PACKET_SIZE));
cursor.write_all (&MAGIC_NUMBER)?; cursor.write_all (&MAGIC_NUMBER)?;
for msg in msgs { for msg in msgs {

View File

@ -61,7 +61,7 @@ impl <R: std::io::Read> Reader <R> {
Ok (u32::from_le_bytes (buf)) Ok (u32::from_le_bytes (buf))
} }
pub fn lv_bytes (r: &mut R, buf: &mut [u8]) -> Result <u32> { fn lv_bytes (r: &mut R, buf: &mut [u8]) -> Result <u32> {
let l = Self::length (r)?; let l = Self::length (r)?;
if usize::try_from (l)? > buf.len () { if usize::try_from (l)? > buf.len () {
return Err (TlvError::CallerBufferTooSmall); return Err (TlvError::CallerBufferTooSmall);