use super::super::simple_up_packet;
use super::{pull_ack, write_preamble, Identifier, MacAddress, Result, SerializablePacket};
use std::io::{Cursor, Write};
#[derive(Debug, Clone)]
pub struct Packet {
pub random_token: u16,
pub gateway_mac: MacAddress,
}
impl Default for Packet {
fn default() -> Packet {
Packet {
random_token: 0,
gateway_mac: MacAddress::from([0; 8]),
}
}
}
simple_up_packet!(Packet, Identifier::PullData);
impl From<Packet> for super::Packet {
fn from(packet: Packet) -> super::Packet {
super::Packet::Up(super::Up::PullData(packet))
}
}
impl Packet {
pub fn new(random_token: u16) -> Packet {
Packet {
random_token,
gateway_mac: MacAddress::from([0; 8]),
}
}
pub fn into_ack(self) -> pull_ack::Packet {
pull_ack::Packet {
random_token: self.random_token,
}
}
}