pub struct DCPBlockRequest {
pub option: u8,
pub suboption: u8,
pub payload: Vec<u8>,
}
impl DCPBlockRequest {
pub fn new(option: u8, suboption: u8, payload: Vec<u8>) -> DCPBlockRequest {
return DCPBlockRequest {
option: option,
suboption: suboption,
payload: payload,
};
}
pub fn compile(&self) -> Vec<u8> {
let mut header: Vec<u8> = Vec::new();
header.push(self.option); header.push(self.suboption); let paylen = self.payload.len() as u16; let mut pay = self.payload.clone();
if (paylen % 2) != 0 {
pay.push(0x00);
}
header.extend_from_slice(&paylen.to_be_bytes());
let mut packet: Vec<u8> = Vec::new();
packet.extend(&header);
packet.extend(&pay);
return packet;
}
}