77 lines
1.5 KiB
Rust
77 lines
1.5 KiB
Rust
use crate::util::pack::{pack_u16, unpack_u16};
|
|
|
|
use super::Packet;
|
|
|
|
#[derive(Clone)]
|
|
pub struct PacketUserList {
|
|
pub page:u16,
|
|
}
|
|
impl PacketUserList {
|
|
pub fn new() -> Self
|
|
{
|
|
Self {
|
|
page:0,
|
|
}
|
|
}
|
|
}
|
|
impl Packet for PacketUserList {
|
|
type Data = Self;
|
|
|
|
fn decode(data:&Vec<u8>, index:&mut usize) -> Result<Self::Data, ()>
|
|
{
|
|
let mut result = Self::new();
|
|
|
|
if data.len() - *index == 2 {
|
|
result.page = unpack_u16(data, index);
|
|
|
|
Ok(result)
|
|
} else {
|
|
Err(())
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#[derive(Clone)]
|
|
pub struct PacketUserListResponseRecord {
|
|
//pub token:UserToken,
|
|
pub handle:String,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct PacketUserListResponse {
|
|
pub status:u16,
|
|
pub records:Vec<PacketUserListResponseRecord>,
|
|
}
|
|
impl PacketUserListResponse {
|
|
pub fn new() -> Self
|
|
{
|
|
Self {
|
|
status:0,
|
|
records:Vec::new(),
|
|
}
|
|
}
|
|
}
|
|
impl Packet for PacketUserListResponse {
|
|
type Data = Self;
|
|
|
|
fn encode(&self) -> Vec<u8>
|
|
{
|
|
let mut result = pack_u16(self.status as u16);
|
|
|
|
result.append(&mut pack_u16(self.records.len() as u16));
|
|
|
|
for record in &self.records {
|
|
let mut chunk = Vec::new(); //record.token.to_vec();
|
|
|
|
// Handle
|
|
let mut bytes = record.handle.as_bytes().to_vec();
|
|
chunk.append(&mut pack_u16(bytes.len() as u16));
|
|
if bytes.len() > 0 { chunk.append(&mut bytes); }
|
|
|
|
result.append(&mut chunk);
|
|
}
|
|
result
|
|
}
|
|
}
|