use jt808::models::{Jt808, Jt808BodySerialize, Jt808BodyTrans, Ver808};
use jt_util::{
bytes::{IBuffRead, IBuffWrite},
bytes_gbk::BytesGBK,
};
#[derive(Debug, Default)]
pub struct Jt0x9101 {
pub ipaddress: BytesGBK,
pub tcp_port: u16,
pub udp_port: u16,
pub channel: u8,
pub data_type: u8,
pub stream_type: u8,
}
impl Jt808BodySerialize for Jt0x9101 {
fn write(&mut self, _ver: &Ver808, buf: &mut dyn IBuffWrite) {
buf.put_u8(self.ipaddress.bytes_len() as u8);
buf.put(self.ipaddress.get_bytes());
buf.put_u16(self.tcp_port);
buf.put_u16(self.udp_port);
buf.put_u8(self.channel);
buf.put_u8(self.data_type);
buf.put_u8(self.stream_type);
}
fn len(&self, _ver: &Ver808) -> usize {
self.ipaddress.bytes_len() + 8
}
}
impl Jt808BodyTrans for Jt0x9101 {
fn fill_new<T>(buf: &mut T, _jt808: &Jt808) -> Self
where
T: IBuffRead,
{
let len = buf.get_u8();
Self {
ipaddress: BytesGBK::new_with_bytes(buf.split_to(len as usize)),
tcp_port: buf.get_u16(),
udp_port: buf.get_u16(),
channel: buf.get_u8(),
data_type: buf.get_u8(),
stream_type: buf.get_u8(),
}
}
}