|
|
@ -111,6 +111,23 @@ impl PSOPacketData for String { |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
|
pub struct ConsumingBlob {
|
|
|
|
pub blob: Vec<u8>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PSOPacketData for ConsumingBlob {
|
|
|
|
fn from_bytes<R: Read>(cursor: &mut R) -> Result<ConsumingBlob, PacketParseError> {
|
|
|
|
let mut blob: Vec<u8> = Vec::new();
|
|
|
|
cursor.read_to_end(&mut blob).map_err(|_| PacketParseError::ReadError)?;
|
|
|
|
Ok(ConsumingBlob {
|
|
|
|
blob: blob,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
fn as_bytes(&self) -> Vec<u8> {
|
|
|
|
self.blob.clone()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait PSOPacket: std::fmt::Debug {
|
|
|
|
// const CMD: u16;
|
|
|
@ -545,4 +562,22 @@ mod test { |
|
|
|
let bytes = test.as_bytes();
|
|
|
|
assert!(bytes[1] == 101);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_consuming_blob() {
|
|
|
|
#[pso_packet(0x6D, manual_flag)]
|
|
|
|
struct SixDee {
|
|
|
|
flag: u32,
|
|
|
|
blob: ConsumingBlob,
|
|
|
|
}
|
|
|
|
|
|
|
|
let pkt = vec![76, 0, 109, 0, 1, 0, 0, 0, 109, 0, 0, 0, 68, 0, 0, 0, 140, 0, 0, 0,
|
|
|
|
51, 0, 0, 0, 84, 220, 255, 254, 253, 1, 254, 240, 33, 254, 240,
|
|
|
|
65, 254, 240, 85, 97, 254, 240, 129, 254, 240, 161, 254, 240, 193,
|
|
|
|
254, 240, 169, 225, 13, 1, 16, 0, 33, 16, 0, 65, 16, 0, 97, 0, 16,
|
|
|
|
1, 64, 15, 82, 15, 100, 15, 118, 0, 0];
|
|
|
|
|
|
|
|
let data = SixDee::from_bytes(&pkt);
|
|
|
|
assert!(pkt == data.unwrap().as_bytes());
|
|
|
|
}
|
|
|
|
}
|