+protocol16 types implemented
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
lib/**/target
|
||||||
Generated
+29
@@ -13,6 +13,20 @@ name = "bitflags"
|
|||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byteorder"
|
||||||
|
version = "1.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bytes"
|
||||||
|
version = "0.4.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
version = "0.1.9"
|
version = "0.1.9"
|
||||||
@@ -31,6 +45,15 @@ name = "glob"
|
|||||||
version = "0.2.11"
|
version = "0.2.11"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "iovec"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ipnetwork"
|
name = "ipnetwork"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
@@ -170,6 +193,9 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "protocol16"
|
name = "protocol16"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
@@ -300,8 +326,11 @@ dependencies = [
|
|||||||
[metadata]
|
[metadata]
|
||||||
"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5"
|
"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5"
|
||||||
"checksum bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4f67931368edf3a9a51d29886d245f1c3db2f1ef0dcc9e35ff70341b78c10d23"
|
"checksum bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4f67931368edf3a9a51d29886d245f1c3db2f1ef0dcc9e35ff70341b78c10d23"
|
||||||
|
"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
|
||||||
|
"checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c"
|
||||||
"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33"
|
"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33"
|
||||||
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
|
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
|
||||||
|
"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08"
|
||||||
"checksum ipnetwork 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3d862c86f7867f19b693ec86765e0252d82e53d4240b9b629815675a0714ad1"
|
"checksum ipnetwork 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3d862c86f7867f19b693ec86765e0252d82e53d4240b9b629815675a0714ad1"
|
||||||
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
||||||
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
|
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
|
||||||
|
|||||||
Generated
+48
@@ -0,0 +1,48 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
[[package]]
|
||||||
|
name = "byteorder"
|
||||||
|
version = "1.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bytes"
|
||||||
|
version = "0.4.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "iovec"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.60"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "protocol16"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi"
|
||||||
|
version = "0.2.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[metadata]
|
||||||
|
"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
|
||||||
|
"checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c"
|
||||||
|
"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08"
|
||||||
|
"checksum libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)" = "d44e80633f007889c7eff624b709ab43c92d708caad982295768a7b13ca3b5eb"
|
||||||
|
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
|
||||||
@@ -7,3 +7,4 @@ edition = "2018"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
bytes = "0.4.12"
|
||||||
+605
-357
File diff suppressed because it is too large
Load Diff
@@ -1,19 +0,0 @@
|
|||||||
pub enum TypeCode {
|
|
||||||
Dictionary = 68,
|
|
||||||
StringArray = 97,
|
|
||||||
Byte = 98,
|
|
||||||
Double = 100,
|
|
||||||
EventData = 101,
|
|
||||||
Float = 102,
|
|
||||||
Integer = 105,
|
|
||||||
Short = 107,
|
|
||||||
Long = 108,
|
|
||||||
BooleanArray = 110,
|
|
||||||
Boolean = 111,
|
|
||||||
OperationResponse = 112,
|
|
||||||
OperationRequest = 113,
|
|
||||||
String = 115,
|
|
||||||
ByteArray = 120,
|
|
||||||
Array = 121,
|
|
||||||
ObjectArray = 122
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
pub enum TypeCode {
|
||||||
|
Unknown = 0,
|
||||||
|
Null = 42,
|
||||||
|
Dictionary = 68,
|
||||||
|
StringArray = 97,
|
||||||
|
Byte = 98,
|
||||||
|
Double = 100,
|
||||||
|
EventData = 101,
|
||||||
|
Float = 102,
|
||||||
|
Integer = 105,
|
||||||
|
Short = 107,
|
||||||
|
Long = 108,
|
||||||
|
BooleanArray = 110,
|
||||||
|
Boolean = 111,
|
||||||
|
OperationResponse = 112,
|
||||||
|
OperationRequest = 113,
|
||||||
|
String = 115,
|
||||||
|
ByteArray = 120,
|
||||||
|
Array = 121,
|
||||||
|
ObjectArray = 122,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<u8> for TypeCode {
|
||||||
|
fn from(v: u8) -> Self {
|
||||||
|
match v {
|
||||||
|
0 => TypeCode::Unknown,
|
||||||
|
42 => TypeCode::Null,
|
||||||
|
68 => TypeCode::Dictionary,
|
||||||
|
97 => TypeCode::StringArray,
|
||||||
|
98 => TypeCode::Byte,
|
||||||
|
100 => TypeCode::Double,
|
||||||
|
101 => TypeCode::EventData,
|
||||||
|
102 => TypeCode::Float,
|
||||||
|
105 => TypeCode::Integer,
|
||||||
|
107 => TypeCode::Short,
|
||||||
|
108 => TypeCode::Long,
|
||||||
|
110 => TypeCode::BooleanArray,
|
||||||
|
111 => TypeCode::Boolean,
|
||||||
|
112 => TypeCode::OperationResponse,
|
||||||
|
113 => TypeCode::OperationRequest,
|
||||||
|
115 => TypeCode::String,
|
||||||
|
120 => TypeCode::ByteArray,
|
||||||
|
121 => TypeCode::Array,
|
||||||
|
122 => TypeCode::ObjectArray,
|
||||||
|
_ => TypeCode::Unknown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub struct EventData {
|
||||||
|
pub code: u8,
|
||||||
|
pub parameters: HashMap<u8, Value>
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub struct OperationResponse {
|
||||||
|
pub code: u8,
|
||||||
|
pub return_code: i16,
|
||||||
|
pub debug_message: String,
|
||||||
|
pub parameters: HashMap<u8, Value>
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub struct OperationRequest {
|
||||||
|
pub code: u8,
|
||||||
|
pub parameters: HashMap<u8, Value>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub enum Value {
|
||||||
|
None,
|
||||||
|
Dictionary(HashMap<String, Value>),
|
||||||
|
StringArray(Vec<String>),
|
||||||
|
Byte(u8),
|
||||||
|
Double(f64),
|
||||||
|
EventData(EventData),
|
||||||
|
Float(f32),
|
||||||
|
Integer(u32),
|
||||||
|
Short(i16),
|
||||||
|
Long(i64),
|
||||||
|
BooleanArray(Vec<bool>),
|
||||||
|
Boolean(bool),
|
||||||
|
OperationResponse(OperationResponse),
|
||||||
|
OperationRequest(OperationRequest),
|
||||||
|
String(String),
|
||||||
|
ByteArray(Vec<u8>),
|
||||||
|
Array(Vec<Value>),
|
||||||
|
ObjectArray(Vec<Value>)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::ops::Index<usize> for Value {
|
||||||
|
type Output = Value;
|
||||||
|
|
||||||
|
fn index(&self, index: usize) -> &Self::Output {
|
||||||
|
match self {
|
||||||
|
Value::Array(v) => &v[index],
|
||||||
|
_ => panic!("Non indexable type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for Value {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Value::String(v) => write!(f, "{}", v),
|
||||||
|
Value::Byte(v) => write!(f, "{}", v),
|
||||||
|
Value::Integer(v) => write!(f, "{}", v),
|
||||||
|
v => write!(f, "{:?}", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user