aboutsummaryrefslogtreecommitdiff
path: root/src/message/handshake/types.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/message/handshake/types.rs')
-rw-r--r--src/message/handshake/types.rs49
1 files changed, 47 insertions, 2 deletions
diff --git a/src/message/handshake/types.rs b/src/message/handshake/types.rs
index 04e1dd0..24d847b 100644
--- a/src/message/handshake/types.rs
+++ b/src/message/handshake/types.rs
@@ -6,9 +6,9 @@ use failure::Error;
use crate::error::ProtocolError;
use crate::primitive::Variant;
+use crate::util;
use crate::Deserialize;
use crate::Serialize;
-use crate::util;
use crate::primitive::VariantMap;
use crate::{HandshakeDeserialize, HandshakeSerialize};
@@ -46,7 +46,7 @@ impl HandshakeDeserialize for VariantMap {
match name {
Variant::String(x) => map.insert(x, value),
- Variant::StringUTF8(x) => map.insert(x, value),
+ Variant::ByteArray(x) => map.insert(x, value),
_ => bail!(ProtocolError::WrongVariant),
};
}
@@ -54,3 +54,48 @@ impl HandshakeDeserialize for VariantMap {
return Ok((pos, map));
}
}
+
+#[test]
+pub fn serialize_variantmap() {
+ let mut test_variantmap = VariantMap::new();
+ test_variantmap.insert("Configured".to_string(), Variant::bool(true));
+ let bytes = [
+ 0, 0, 0, 2, 0, 0, 0, 10, 0, 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0,
+ 117, 0, 114, 0, 101, 0, 100, 0, 0, 0, 1, 0, 1,
+ ]
+ .to_vec();
+ assert_eq!(
+ HandshakeSerialize::serialize(&test_variantmap).unwrap(),
+ bytes
+ );
+}
+
+#[test]
+pub fn deserialize_variantmap() {
+ let test_bytes: &[u8] = &[
+ 0, 0, 0, 2, 0, 0, 0, 10, 0, 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0,
+ 117, 0, 114, 0, 101, 0, 100, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1,
+ ];
+ let mut test_variantmap = VariantMap::new();
+ test_variantmap.insert("Configured".to_string(), Variant::bool(true));
+
+ let (len, res): (usize, VariantMap) = HandshakeDeserialize::parse(test_bytes).unwrap();
+
+ assert_eq!(len, 39);
+ assert_eq!(res, test_variantmap);
+}
+
+#[test]
+pub fn deserialize_variantmap_utf8() {
+ let test_bytes: &[u8] = &[
+ 0, 0, 0, 2, 0, 0, 0, 12, 0, 0, 0, 0, 10, 67, 111, 110, 102, 105, 103, 117, 114, 101, 100,
+ 0, 0, 0, 1, 0, 1, 0, 0, 0, 1,
+ ];
+ let mut test_variantmap = VariantMap::new();
+ test_variantmap.insert("Configured".to_string(), Variant::bool(true));
+
+ let (len, res): (usize, VariantMap) = HandshakeDeserialize::parse(test_bytes).unwrap();
+
+ assert_eq!(len, 29);
+ assert_eq!(res, test_variantmap);
+}