mqtt/control/variable_header/
keep_alive.rs1use std::io::{self, Read, Write};
2
3use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
4
5use crate::control::variable_header::VariableHeaderError;
6use crate::{Decodable, Encodable};
7
8#[derive(Debug, Eq, PartialEq, Copy, Clone)]
10pub struct KeepAlive(pub u16);
11
12impl Encodable for KeepAlive {
13 fn encode<W: Write>(&self, writer: &mut W) -> Result<(), io::Error> {
14 writer.write_u16::<BigEndian>(self.0)
15 }
16
17 fn encoded_length(&self) -> u32 {
18 2
19 }
20}
21
22impl Decodable for KeepAlive {
23 type Error = VariableHeaderError;
24 type Cond = ();
25
26 fn decode_with<R: Read>(reader: &mut R, _rest: ()) -> Result<KeepAlive, VariableHeaderError> {
27 reader.read_u16::<BigEndian>().map(KeepAlive).map_err(From::from)
28 }
29}