mqtt4bytes/packets/
pubrel.rs1use crate::*;
2use bytes::{Buf, BufMut, Bytes, BytesMut};
3
4#[derive(Debug, Clone, PartialEq)]
6pub struct PubRel {
7 pub pkid: u16,
8}
9
10impl PubRel {
11 pub fn new(pkid: u16) -> PubRel {
12 PubRel { pkid }
13 }
14
15 pub(crate) fn assemble(fixed_header: FixedHeader, mut bytes: Bytes) -> Result<Self, Error> {
16 if fixed_header.remaining_len != 2 {
17 return Err(Error::PayloadSizeIncorrect);
18 }
19
20 let variable_header_index = fixed_header.fixed_len;
21 bytes.advance(variable_header_index);
22 let pkid = bytes.get_u16();
23 let pubrel = PubRel { pkid };
24
25 Ok(pubrel)
26 }
27
28 pub fn write(&self, payload: &mut BytesMut) -> Result<usize, Error> {
29 let o: &[u8] = &[0x62, 0x02];
30 payload.put_slice(o);
31 payload.put_u16(self.pkid);
32 Ok(4)
33 }
34}