Photon fragments
This commit is contained in:
@@ -0,0 +1,361 @@
|
||||
use photon_protocol::*;
|
||||
|
||||
use std::io::{Read, Cursor};
|
||||
|
||||
#[test]
|
||||
fn deserialize_dictionary() {
|
||||
let value = vec![
|
||||
68, 115, 115, 0, 2, 0, 8, 116, 101, 115, 116, 75, 101, 121, 49, 0, 10, 116, 101, 115,
|
||||
116, 86, 97, 108, 117, 101, 49, 0, 8, 116, 101, 115, 116, 75, 101, 121, 50, 0, 10, 116,
|
||||
101, 115, 116, 86, 97, 108, 117, 101, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
match value {
|
||||
Value::Dictionary(v) => {
|
||||
return assert_eq!(
|
||||
v.get("testKey1"),
|
||||
Some(&Value::String("testValue1".to_owned()))
|
||||
)
|
||||
}
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_string_array() {
|
||||
let value = vec![
|
||||
121, 0, 2, 115, 0, 5, 116, 101, 115, 116, 49, 0, 5, 116, 101, 115, 116, 50, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
|
||||
match value {
|
||||
Value::Array(v) => {
|
||||
if let Value::String(val) = &v[0] {
|
||||
assert_eq!(val, &"test1".to_owned());
|
||||
}
|
||||
if let Value::String(val) = &v[1] {
|
||||
assert_eq!(val, &"test2".to_owned());
|
||||
}
|
||||
return;
|
||||
}
|
||||
Value::StringArray(v) => {
|
||||
return assert_eq!(vec!["test1".to_owned(), "test2".to_owned()], v)
|
||||
}
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_deserialize_byte() {
|
||||
let value = vec![98, 6];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
match value {
|
||||
Value::Byte(v) => return assert_eq!(v, 6),
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_double() {
|
||||
let value = vec![100, 64, 147, 74, 51, 51, 51, 51, 51, 0, 0, 0, 0, 0, 0, 0];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
match value {
|
||||
Value::Double(v) => return assert_eq!(v, 1234.55),
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_event_data() {
|
||||
let value = vec![
|
||||
101, 100, 0, 2, 0, 115, 0, 5, 116, 101, 115, 116, 49, 1, 115, 0, 5, 116, 101, 115, 116,
|
||||
50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
match value {
|
||||
Value::EventData(v) => {
|
||||
assert_eq!(v.code, 100);
|
||||
assert_eq!(
|
||||
v.parameters.get(&0).unwrap(),
|
||||
&Value::String("test1".to_owned())
|
||||
);
|
||||
return;
|
||||
}
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_float() {
|
||||
let value = vec![102, 68, 154, 81, 154, 0, 0, 0];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
match value {
|
||||
Value::Float(v) => return assert_eq!(v, 1234.55),
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_integer() {
|
||||
let value = vec![105, 0, 0, 4, 210, 0, 0, 0];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
match value {
|
||||
Value::Integer(v) => return assert_eq!(v, 1234),
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_short() {
|
||||
let value = vec![107, 4, 210, 0];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
match value {
|
||||
Value::Short(v) => return assert_eq!(v, 1234),
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_long() {
|
||||
let value = vec![108, 0, 0, 0, 0, 0, 0, 4, 210, 0, 0, 0, 0, 0, 0, 0];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
match value {
|
||||
Value::Long(v) => return assert_eq!(v, 1234),
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_integer_array() {
|
||||
let value = vec![121, 0, 2, 105, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
match value {
|
||||
Value::Array(v) => {
|
||||
if let Value::Integer(val) = v[0] {
|
||||
assert_eq!(val, 0);
|
||||
}
|
||||
if let Value::Integer(val) = v[1] {
|
||||
assert_eq!(val, 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_boolean() {
|
||||
let value = vec![111, 1];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
match value {
|
||||
Value::Boolean(v) => return assert_eq!(v, true),
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_operation_response() {
|
||||
let value = vec![
|
||||
112, 100, 0, 100, 42, 0, 2, 0, 115, 0, 5, 116, 101, 115, 116, 49, 1, 115, 0, 5, 116,
|
||||
101, 115, 116, 50, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
match value {
|
||||
Value::OperationResponse(v) => {
|
||||
assert_eq!(v.code, 100);
|
||||
assert_eq!(v.return_code, 100);
|
||||
assert_eq!(
|
||||
v.parameters.get(&1).unwrap(),
|
||||
&Value::String("test2".to_owned())
|
||||
);
|
||||
return;
|
||||
}
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_operation_request() {
|
||||
let value = vec![
|
||||
113, 100, 0, 2, 0, 115, 0, 5, 116, 101, 115, 116, 49, 1, 115, 0, 5, 116, 101, 115, 116,
|
||||
50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
match value {
|
||||
Value::OperationRequest(v) => {
|
||||
assert_eq!(v.code, 100);
|
||||
assert_eq!(
|
||||
v.parameters.get(&1).unwrap(),
|
||||
&Value::String("test2".to_owned())
|
||||
);
|
||||
return;
|
||||
}
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_string() {
|
||||
let value = vec![
|
||||
115, 0, 12, 116, 101, 115, 116, 95, 109, 101, 115, 115, 97, 103, 101, 0,
|
||||
];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
match value {
|
||||
Value::String(v) => return assert_eq!(&v, "test_message"),
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_byte_array() {
|
||||
let value = vec![120, 0, 0, 0, 2, 6, 7, 0];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
match value {
|
||||
Value::ByteArray(v) => {
|
||||
assert_eq!(&v[0], &6);
|
||||
assert_eq!(&v[1], &7);
|
||||
return;
|
||||
}
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_array_dictionary() {
|
||||
let value = vec![
|
||||
121, 0, 1, 68, 105, 115, 0, 1, 0, 0, 0, 0, 0, 5, 116, 101, 115, 116, 49, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
match value {
|
||||
Value::Array(v) => {
|
||||
if let Value::Dictionary(val) = &v[0] {
|
||||
assert_eq!(val.get("0").unwrap(), &Value::String("test1".to_owned()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_array_byte_array() {
|
||||
let value = vec![121, 0, 1, 120, 0, 0, 0, 4, 0, 2, 4, 8, 0, 0, 0, 0];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
|
||||
match value {
|
||||
Value::Array(v) => {
|
||||
if let Value::ByteArray(val) = &v[0] {
|
||||
assert_eq!(val[0], 0);
|
||||
assert_eq!(val[1], 2);
|
||||
assert_eq!(val[2], 4);
|
||||
assert_eq!(val[3], 8);
|
||||
return;
|
||||
}
|
||||
}
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_array_array() {
|
||||
let value = vec![
|
||||
121, 0, 1, 121, 0, 3, 105, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0,
|
||||
];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
match value {
|
||||
Value::Array(v) => {
|
||||
if let Value::Integer(val) = &v[0][0] {
|
||||
assert_eq!(val, &1);
|
||||
}
|
||||
if let Value::Integer(val) = &v[0][1] {
|
||||
assert_eq!(val, &2);
|
||||
}
|
||||
if let Value::Integer(val) = &v[0][2] {
|
||||
assert_eq!(val, &3);
|
||||
}
|
||||
return;
|
||||
}
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_object_array() {
|
||||
let value = vec![
|
||||
122, 0, 2, 115, 0, 5, 116, 101, 115, 116, 49, 115, 0, 5, 116, 101, 115, 116, 50, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
let mut buf = Cursor::new(&value[..]);
|
||||
let result = buf.decode();
|
||||
assert!(result.is_ok(), "Unimplemented!");
|
||||
let value = result.unwrap();
|
||||
|
||||
match value {
|
||||
Value::ObjectArray(v) => {
|
||||
if let Value::Object(val) = &*v[0] {
|
||||
assert_eq!(**val, Value::String("test1".to_owned()));
|
||||
}
|
||||
if let Value::Object(val) = &*v[1] {
|
||||
assert_eq!(**val, Value::String("test2".to_owned()));
|
||||
}
|
||||
}
|
||||
_ => assert!(false),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
use photon_protocol;
|
||||
|
||||
use photon_protocol::Message;
|
||||
use photon_protocol::EventData;
|
||||
use photon_protocol::OperationRequest;
|
||||
use photon_protocol::OperationResponse;
|
||||
use photon_protocol::Value;
|
||||
use photon_protocol::Parameters;
|
||||
|
||||
#[test]
|
||||
fn test_single_event_message()
|
||||
{
|
||||
let header = vec![
|
||||
0x00, 0x01, // PeerID
|
||||
0x01, // CrcEnabled
|
||||
0x01, // CommandCount
|
||||
0x00, 0x00, 0x00, 0x01, // Timestamp
|
||||
0x00, 0x00, 0x00, 0x01, // Challenge
|
||||
];
|
||||
|
||||
let photon_command = vec![
|
||||
0x06, // Type
|
||||
0x01, // ChannelID
|
||||
0x01, // Flags
|
||||
0x04, // ReservedByte
|
||||
0x00, 0x00, 0x00, 0x1a, // Length
|
||||
0x00, 0x00, 0x00, 0x01, // ReliableSequenceNumber
|
||||
];
|
||||
|
||||
let message = vec![
|
||||
0x01, // ??
|
||||
0x04, // MsgType (Event)
|
||||
// Payload
|
||||
0x64, 0x00, 0x02, // Key
|
||||
0x00, 0x73, // String type
|
||||
0x00, 0x05, // String length
|
||||
0x74, 0x65, 0x73, 0x74, 0x31 //test1
|
||||
];
|
||||
|
||||
let mut photon = photon_protocol::Photon::new();
|
||||
|
||||
let decoded = photon.decode(
|
||||
&[&header[..], &photon_command[..], &message[..]].concat());
|
||||
|
||||
assert!(decoded.len() == 1);
|
||||
let parameters: Parameters =
|
||||
[(0, Value::String("test1".to_owned()))]
|
||||
.iter().cloned().collect();
|
||||
assert_eq!(decoded[0], Message::Event(EventData{ code: 100, parameters}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fragmented_event_message()
|
||||
{
|
||||
let header = vec![
|
||||
0x00, 0x01, // PeerID
|
||||
0x01, // CrcEnabled
|
||||
0x01, // CommandCount
|
||||
0x00, 0x00, 0x00, 0x01, // Timestamp
|
||||
0x00, 0x00, 0x00, 0x01, // Challenge
|
||||
];
|
||||
|
||||
let mut photon = photon_protocol::Photon::new();
|
||||
|
||||
let photon_command = vec![
|
||||
0x08, // Type
|
||||
0x01, // ChannelID
|
||||
0x01, // Flags
|
||||
0x04, // ReservedByte
|
||||
0x00, 0x00, 0x00, 0x22, // Length
|
||||
0x00, 0x00, 0x00, 0x01, // ReliableSequenceNumber
|
||||
0x00, 0x00, 0x00, 0x01, // SequenceNumber
|
||||
0x00, 0x00, 0x00, 0x03, // FragmentCount
|
||||
0x00, 0x00, 0x00, 0x01, // FragmentNumber
|
||||
0x00, 0x00, 0x00, 0x1a, // TotalLength
|
||||
0x00, 0x00, 0x00, 0x01, // OperationLength
|
||||
];
|
||||
|
||||
let message = vec![
|
||||
0x01, // ??
|
||||
0x04, // MsgType (Event)
|
||||
// Payload
|
||||
];
|
||||
|
||||
let decoded = photon.decode(
|
||||
&[&header[..], &photon_command[..], &message[..]].concat());
|
||||
assert!(decoded.len() == 0);
|
||||
|
||||
let photon_command = vec![
|
||||
0x08, // Type
|
||||
0x01, // ChannelID
|
||||
0x01, // Flags
|
||||
0x04, // ReservedByte
|
||||
0x00, 0x00, 0x00, 0x27, // Length
|
||||
0x00, 0x00, 0x00, 0x01, // ReliableSequenceNumber
|
||||
0x00, 0x00, 0x00, 0x01, // SequenceNumber
|
||||
0x00, 0x00, 0x00, 0x03, // FragmentCount
|
||||
0x00, 0x00, 0x00, 0x02, // FragmentNumber
|
||||
0x00, 0x00, 0x00, 0x1a, // TotalLength
|
||||
0x00, 0x00, 0x00, 0x01, // OperationLength
|
||||
];
|
||||
|
||||
let message = vec![
|
||||
// Payload
|
||||
0x64, 0x00, 0x02, // Key
|
||||
0x00, 0x73, // String type
|
||||
0x00, 0x05, // String length
|
||||
];
|
||||
|
||||
let decoded = photon.decode(
|
||||
&[&header[..], &photon_command[..], &message[..]].concat());
|
||||
assert!(decoded.len() == 0);
|
||||
|
||||
let photon_command = vec![
|
||||
0x08, // Type
|
||||
0x01, // ChannelID
|
||||
0x01, // Flags
|
||||
0x04, // ReservedByte
|
||||
0x00, 0x00, 0x00, 0x25, // Length
|
||||
0x00, 0x00, 0x00, 0x01, // ReliableSequenceNumber
|
||||
0x00, 0x00, 0x00, 0x01, // SequenceNumber
|
||||
0x00, 0x00, 0x00, 0x03, // FragmentCount
|
||||
0x00, 0x00, 0x00, 0x03, // FragmentNumber
|
||||
0x00, 0x00, 0x00, 0x1a, // TotalLength
|
||||
0x00, 0x00, 0x00, 0x01, // OperationLength
|
||||
];
|
||||
|
||||
let message = vec![
|
||||
0x74, 0x65, 0x73, 0x74, 0x31 //test1
|
||||
];
|
||||
|
||||
let decoded = photon.decode(
|
||||
&[&header[..], &photon_command[..], &message[..]].concat());
|
||||
assert_eq!(decoded.len(), 1);
|
||||
|
||||
let parameters: Parameters =
|
||||
[(0, Value::String("test1".to_owned()))]
|
||||
.iter().cloned().collect();
|
||||
assert_eq!(decoded[0], Message::Event(EventData{ code: 100, parameters}));
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_two_event_messages()
|
||||
{
|
||||
let payload = vec![
|
||||
0x00, 0x00,
|
||||
0x00,
|
||||
0x02,
|
||||
0x72, 0xe9, 0xe2, 0x84,
|
||||
0x11, 0x63, 0x88, 0x88,
|
||||
|
||||
0x07,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00, 0x00, 0x00, 0x45,
|
||||
0x00, 0x00, 0x16, 0x8e,
|
||||
0x00, 0x00, 0x45, 0x2b,
|
||||
0xf3, 0x04, 0x02, 0x00, 0x02, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa, 0xb7, 0x36, 0x01, 0x78, 0x00, 0x00, 0x00, 0x20, 0x03, 0x6b, 0xc9, 0x04, 0xc1, 0xe2, 0x62, 0xd7, 0x08, 0x6b, 0xb0, 0x91, 0xc1, 0x2a, 0x80, 0x1b, 0xc2, 0x26, 0x00, 0x00, 0xb0, 0x40, 0xd8, 0xe6, 0x53, 0xc1, 0x8f, 0xcd, 0xc, 0xc2, 0x00, 0x00,
|
||||
|
||||
0x06,
|
||||
0x00,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00, 0x00, 0x00, 0x1b,
|
||||
0x00, 0x00, 0x16, 0x8f,
|
||||
0xf3, 0x04, 0x01, 0x00, 0x02, 0x00, 0x69, 0x00, 0xa, 0xf6, 0xdf, 0xfc, 0x6b, 0x00, 0x01
|
||||
];
|
||||
|
||||
let mut photon = photon_protocol::Photon::new();
|
||||
|
||||
let decoded = photon.decode(&payload);
|
||||
|
||||
assert!(decoded.len() == 2);
|
||||
let parameters: Parameters =
|
||||
[
|
||||
(0x01, Value::ByteArray(vec![
|
||||
3, 107, 201, 4, 193, 226, 98, 215, 8, 107, 176, 145, 193,
|
||||
42, 128, 27, 194, 38, 0, 0, 176, 64, 216, 230, 83, 193,
|
||||
143, 205, 12, 194, 0, 0])),
|
||||
(0x00, Value::Long(702262))
|
||||
]
|
||||
.iter().cloned().collect();
|
||||
assert_eq!(decoded[0], Message::Event(EventData{ code: 2, parameters}));
|
||||
|
||||
let parameters: Parameters =
|
||||
[
|
||||
(0x00, Value::Integer(718559)),
|
||||
(0xfc, Value::Short(1))
|
||||
]
|
||||
.iter().cloned().collect();
|
||||
assert_eq!(decoded[1], Message::Event(EventData{ code: 1, parameters}));
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_request_message()
|
||||
{
|
||||
let payload = vec![
|
||||
0x7d, 0xd3,
|
||||
0x00,
|
||||
0x01,
|
||||
0x00, 0x04, 0xcc, 0xb6,
|
||||
0x11, 0x63, 0x88, 0x88,
|
||||
|
||||
0x06,
|
||||
0x00,
|
||||
0x01,
|
||||
0x04,
|
||||
0x00, 0x00, 0x00, 0x2a,
|
||||
0x00, 0x00, 0x00, 0x19,
|
||||
0xf3, 0x02, 0x01, 0x00, 0x03, 0x00,
|
||||
0x79, 0x00, 0x02, 0x66, 0xc1, 0xd3, 0x61, 0x20, 0xc2, 0x27, 0xc, 0xcd, 0x01, 0x62,
|
||||
0x00, 0xfd, // key
|
||||
0x73, // String type
|
||||
0x00, 0x05, // String length
|
||||
0x74, 0x65, 0x73, 0x74, 0x31 // test1
|
||||
];
|
||||
|
||||
let mut photon = photon_protocol::Photon::new();
|
||||
let decoded = photon.decode(&payload);
|
||||
|
||||
assert!(decoded.len() == 1);
|
||||
let parameters: Parameters =
|
||||
[
|
||||
(0x00, Value::Array(vec![Value::Float(-26.422424), Value::Float(-41.7625)])),
|
||||
(0x01, Value::Byte(0)),
|
||||
(0xfd, Value::String("test1".to_owned()))
|
||||
|
||||
]
|
||||
.iter().cloned().collect();
|
||||
assert_eq!(decoded[0], Message::Request(OperationRequest { code: 1, parameters}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_response_message()
|
||||
{
|
||||
let payload = vec![
|
||||
0x00, 0x00,
|
||||
0x00,
|
||||
0x02,
|
||||
0x72, 0xea, 0x1d, 0x6a,
|
||||
0x11, 0x63, 0x88, 0x88,
|
||||
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00, 0x00, 0x00, 0x14,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x24, 0x00, 0x04, 0xd7, 0x1a,
|
||||
|
||||
0x06,
|
||||
0x00,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00, 0x00, 0x00, 0xb2,
|
||||
0x00, 0x00, 0x17, 0x71,
|
||||
0xf3, 0x03, 0x01, 0x00, 0x00, 0x2a, 0x00, 0xa, 0x00, 0x69, 0x18, 0xf2, 0x79, 0x68, 0x01, 0x73, 0x00, 0x5d, 0x40, 0x49, 0x53, 0x4c, 0x41, 0x4e, 0x44, 0x40, 0x65, 0x66, 0x33, 0x37, 0x39, 0x34, 0x64, 0x61, 0x2d, 0x38, 0x66, 0x38, 0x33, 0x2d, 0x34, 0x33, 0x34, 0x30, 0x2d, 0x62, 0x66, 0x35, 0x32, 0x2d, 0x36, 0x38, 0x31, 0x31, 0x37, 0x61, 0x30, 0x36, 0x37, 0x32, 0x65, 0x34, 0x7c, 0x57, 0x65, 0x64, 0x72, 0x6f, 0x77, 0x79, 0x63, 0x7a, 0x4a, 0x61, 0x6b, 0x75, 0x62, 0x7c, 0x36, 0x33, 0x37, 0x30, 0x37, 0x35, 0x33, 0x37, 0x38, 0x38, 0x30, 0x33, 0x31, 0x38, 0x33, 0x39, 0x33, 0x35, 0x7c, 0x57, 0x65, 0x64, 0x72, 0x6f, 0x77, 0x79, 0x63, 0x7a, 0x4a, 0x61, 0x6b, 0x75, 0x62, 0x02, 0x79, 0x00, 0x00, 0x78, 0x03, 0x79, 0x00, 0x00, 0x73, 0x04, 0x79, 0x00, 0x00, 0x73, 0x05, 0x78, 0x00, 0x00, 0x00, 0x00, 0x06, 0x79, 0x00, 0x01, 0x79, 0x00, 0x01, 0x69, 0xff, 0xff, 0xff, 0xff, 0x07, 0x79, 0x00, 0x01, 0x79, 0x00, 0x01, 0x69, 0xff, 0xff, 0xff, 0xff, 0x08, 0x78, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x6b, 0x00, 0xa6
|
||||
];
|
||||
|
||||
let mut photon = photon_protocol::Photon::new();
|
||||
|
||||
let decoded = photon.decode(&payload);
|
||||
|
||||
assert_eq!(decoded.len(), 1);
|
||||
let parameters: Parameters =
|
||||
[
|
||||
(0x00, Value::Integer(418543976)),
|
||||
(0x01, Value::String("@ISLAND@ef3794da-8f83-4340-bf52-68117a0672e4|WedrowyczJakub|637075378803183935|WedrowyczJakub".to_owned()))
|
||||
|
||||
]
|
||||
.iter().cloned().collect();
|
||||
assert_eq!(decoded[0], Message::Response(OperationResponse { code: 1, return_code: 0, debug_message: "None".to_owned(), parameters}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user