plabble-codec 0.1.0

Plabble Transport Protocol codec
Documentation
use crate::{
    abstractions::MAC_SIZE,
    codec::{header::ResponseHeader, ptp_packet::PtpPacket},
};

use super::ResponseBody;

/// The response packet
///
/// # Fields
///
/// * `header` - the header of the packet
/// * `body` - the body of the packet
/// * `mac` - the mac of the packet (optional)
pub struct ResponsePacket {
    pub header: ResponseHeader,
    pub body: ResponseBody,
    pub mac: Option<[u8; MAC_SIZE]>,
}

impl PtpPacket<ResponseHeader, ResponseBody> for ResponsePacket {
    fn get_header(&self) -> &ResponseHeader {
        &self.header
    }

    fn get_body(&self) -> &ResponseBody {
        &self.body
    }

    fn new(header: ResponseHeader, body: ResponseBody, mac: Option<[u8; MAC_SIZE]>) -> Self {
        Self { header, body, mac }
    }

    fn get_mac(&self) -> Option<&[u8; MAC_SIZE]> {
        self.mac.as_ref()
    }
}