aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Audron <audron@cocaine.farm>2025-02-22 22:59:01 +0100
committerMax Audron <audron@cocaine.farm>2025-02-22 22:59:01 +0100
commitb8ad94cd5061445a45d0790eee36014d34ad6817 (patch)
treefb7d11e136b968d2f2b3593ba9163894baed8912 /src
parentupdate dependencies and fix errors (diff)
replace deprecated failure crate with thiserror
this changes the public API in that all our methods now return a proper ProtocolError crate. Needed change anyways to properly deal with all our errors in the long run. Will still need to do a pass through the crate to remove all existing unwraps where it makes sense.
Diffstat (limited to 'src')
-rw-r--r--src/error/mod.rs30
-rw-r--r--src/lib.rs26
-rw-r--r--src/message/handshake/clientinit.rs10
-rw-r--r--src/message/handshake/clientinitack.rs20
-rw-r--r--src/message/handshake/clientinitreject.rs10
-rw-r--r--src/message/handshake/clientlogin.rs15
-rw-r--r--src/message/handshake/clientloginack.rs10
-rw-r--r--src/message/handshake/clientloginreject.rs10
-rw-r--r--src/message/handshake/connack.rs6
-rw-r--r--src/message/handshake/mod.rs5
-rw-r--r--src/message/handshake/sessioninit.rs10
-rw-r--r--src/message/handshake/types.rs25
-rw-r--r--src/message/signalproxy/heartbeat.rs9
-rw-r--r--src/message/signalproxy/initdata.rs5
-rw-r--r--src/message/signalproxy/initrequest.rs5
-rw-r--r--src/message/signalproxy/mod.rs34
-rw-r--r--src/message/signalproxy/objects/backlogmanager.rs11
-rw-r--r--src/message/signalproxy/rpccall.rs5
-rw-r--r--src/message/signalproxy/syncmessage.rs5
-rw-r--r--src/primitive/bufferinfo.rs8
-rw-r--r--src/primitive/datetime.rs14
-rw-r--r--src/primitive/message.rs33
-rw-r--r--src/primitive/signedint.rs20
-rw-r--r--src/primitive/string.rs23
-rw-r--r--src/primitive/stringlist.rs16
-rw-r--r--src/primitive/unsignedint.rs32
-rw-r--r--src/primitive/variant.rs10
-rw-r--r--src/primitive/variantlist.rs7
-rw-r--r--src/primitive/variantmap.rs7
29 files changed, 178 insertions, 243 deletions
diff --git a/src/error/mod.rs b/src/error/mod.rs
index 5553987..b415c98 100644
--- a/src/error/mod.rs
+++ b/src/error/mod.rs
@@ -1,22 +1,26 @@
- #[derive(Debug, Fail)]
+use thiserror::Error;
+
+#[derive(Debug, Error)]
pub enum ProtocolError {
- #[fail(display = "message has wrong type")]
+ #[error("message has wrong type")]
WrongMsgType,
- #[fail(display = "bool value is neither 0 nor 1")]
+ #[error("bool value is neither 0 nor 1")]
BoolOutOfRange,
- #[fail(display = "QVariant is not known")]
+ #[error("QVariant is not known")]
UnknownVariant,
- #[fail(display = "wrong variant has been given")]
+ #[error("wrong variant has been given")]
WrongVariant,
- #[fail(display = "io error")]
- IOError(std::io::Error),
- #[fail(display = "could not convert from int")]
- TryFromIntError(std::num::TryFromIntError),
- #[fail(display = "utf8 error")]
- Utf8Error(std::string::FromUtf8Error),
- #[fail(display = "failed to parse char as utf16")]
+ #[error("io error: {0}")]
+ IOError(#[from] std::io::Error),
+ #[error("could not convert from int: {0}")]
+ TryFromIntError(#[from] std::num::TryFromIntError),
+ #[error("utf8 error: {0}")]
+ Utf8Error(#[from] std::string::FromUtf8Error),
+ #[error("errored to parse char as utf16")]
CharError,
- }
+ #[error("failed to deal with time: {0}")]
+ TimeError(#[from] time::error::ComponentRange),
+}
// impl std::error::Error for ErrorKind {}
//
diff --git a/src/lib.rs b/src/lib.rs
index 877b31a..339b2ce 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -10,9 +10,6 @@ extern crate self as libquassel;
#[macro_use]
mod util;
-#[macro_use]
-extern crate failure;
-
/// Quassel Structures for serialization and deserialization
pub mod message;
@@ -34,63 +31,64 @@ pub mod frame;
#[cfg(all(feature = "client", feature = "server"))]
compile_error!("feature \"client\" and feature \"server\" cannot be enabled at the same time");
+use crate::error::ProtocolError;
+
/// Traits for Serialization of objects
pub mod serialize {
- use failure::Error;
+ use crate::error::ProtocolError;
/// Serialization of types and structs to the quassel byteprotocol
pub trait Serialize {
- fn serialize(&self) -> Result<Vec<u8>, Error>;
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError>;
}
/// Serialization of UTF-8 based Strings to the quassel byteprotocol
pub trait SerializeUTF8 {
- fn serialize_utf8(&self) -> Result<Vec<u8>, Error>;
+ fn serialize_utf8(&self) -> Result<Vec<u8>, ProtocolError>;
}
pub trait SerializeVariant {
- fn serialize_variant(&self) -> Result<Vec<u8>, Error>;
+ fn serialize_variant(&self) -> Result<Vec<u8>, ProtocolError>;
}
}
/// Traits for parsing objects
pub mod deserialize {
- use failure::Error;
+ use crate::error::ProtocolError;
/// Deserialization of types and structs to the quassel byteprotocol
pub trait Deserialize {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error>
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError>
where
Self: std::marker::Sized;
}
/// Deserialization of UTF-8 based Strings to the quassel byteprotocol
pub trait DeserializeUTF8 {
- fn parse_utf8(b: &[u8]) -> Result<(usize, Self), Error>
+ fn parse_utf8(b: &[u8]) -> Result<(usize, Self), ProtocolError>
where
Self: std::marker::Sized;
}
pub trait DeserializeVariant {
- fn parse_variant(b: &[u8]) -> Result<(usize, Self), Error>
+ fn parse_variant(b: &[u8]) -> Result<(usize, Self), ProtocolError>
where
Self: std::marker::Sized;
}
}
-use failure::Error;
/// HandshakeSerialize implements the serialization needed during the handhake phase.
///
/// The protocol has some minor differences during this phase compared to the regular parsing.
pub trait HandshakeSerialize {
- fn serialize(&self) -> Result<Vec<u8>, Error>;
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError>;
}
/// HandshakeDeserialize implements the deserialization needed during the handhake phase.
///
/// The protocol has some minor differences during this phase compared to the regular parsing.
pub trait HandshakeDeserialize {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error>
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError>
where
Self: std::marker::Sized;
}
diff --git a/src/message/handshake/clientinit.rs b/src/message/handshake/clientinit.rs
index d21d6aa..32e8595 100644
--- a/src/message/handshake/clientinit.rs
+++ b/src/message/handshake/clientinit.rs
@@ -1,8 +1,7 @@
+use crate::error::ProtocolError;
use crate::primitive::{StringList, Variant, VariantMap};
use crate::HandshakeSerialize;
-use failure::Error;
-
/// ClientInit is the Initial message send to the core after establishing a base layer comunication.
///
/// Features
@@ -44,12 +43,9 @@ pub struct ClientInit {
}
impl HandshakeSerialize for ClientInit {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
let mut values: VariantMap = VariantMap::with_capacity(5);
- values.insert(
- "MsgType".to_string(),
- Variant::String("ClientInit".to_string()),
- );
+ values.insert("MsgType".to_string(), Variant::String("ClientInit".to_string()));
values.insert(
"ClientVersion".to_string(),
Variant::String(self.client_version.clone()),
diff --git a/src/message/handshake/clientinitack.rs b/src/message/handshake/clientinitack.rs
index a259f9c..610cdc0 100644
--- a/src/message/handshake/clientinitack.rs
+++ b/src/message/handshake/clientinitack.rs
@@ -1,8 +1,7 @@
+use crate::error::ProtocolError;
use crate::primitive::{Variant, VariantList, VariantMap};
use crate::HandshakeSerialize;
-use failure::Error;
-
/// ClientInitAck is received when the initialization was successfull
#[derive(Debug, Clone)]
pub struct ClientInitAck {
@@ -21,17 +20,14 @@ pub struct ClientInitAck {
}
impl HandshakeSerialize for ClientInitAck {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
let mut values: VariantMap = VariantMap::with_capacity(6);
values.insert(
"MsgType".to_string(),
Variant::String("ClientInitAck".to_string()),
);
values.insert("CoreFeatures".to_string(), Variant::u32(self.core_features));
- values.insert(
- "Configured".to_string(),
- Variant::bool(self.core_configured),
- );
+ values.insert("Configured".to_string(), Variant::bool(self.core_configured));
values.insert(
"StorageBackends".to_string(),
Variant::VariantList(self.storage_backends.clone()),
@@ -55,15 +51,9 @@ impl From<VariantMap> for ClientInitAck {
// TODO make this compatible with older clients
core_features: 0,
core_configured: match_variant!(input.get("Configured").unwrap(), Variant::bool),
- storage_backends: match_variant!(
- input.get("StorageBackends").unwrap(),
- Variant::VariantList
- ),
+ storage_backends: match_variant!(input.get("StorageBackends").unwrap(), Variant::VariantList),
#[cfg(feature = "authenticators")]
- authenticators: match_variant!(
- input.get("Authenticators").unwrap(),
- Variant::VariantList
- ),
+ authenticators: match_variant!(input.get("Authenticators").unwrap(), Variant::VariantList),
feature_list: match_variant!(input.get("FeatureList").unwrap(), Variant::StringList),
}
}
diff --git a/src/message/handshake/clientinitreject.rs b/src/message/handshake/clientinitreject.rs
index d93413d..8c2fd34 100644
--- a/src/message/handshake/clientinitreject.rs
+++ b/src/message/handshake/clientinitreject.rs
@@ -1,8 +1,7 @@
+use crate::error::ProtocolError;
use crate::primitive::{Variant, VariantMap};
use crate::HandshakeSerialize;
-use failure::Error;
-
/// ClientInitReject is received when the initialization fails
#[derive(Debug, Clone)]
pub struct ClientInitReject {
@@ -11,16 +10,13 @@ pub struct ClientInitReject {
}
impl HandshakeSerialize for ClientInitReject {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
let mut values: VariantMap = VariantMap::with_capacity(2);
values.insert(
"MsgType".to_string(),
Variant::String("ClientInitReject".to_string()),
);
- values.insert(
- "ErrorString".to_string(),
- Variant::String(self.error.clone()),
- );
+ values.insert("ErrorString".to_string(), Variant::String(self.error.clone()));
return HandshakeSerialize::serialize(&values);
}
}
diff --git a/src/message/handshake/clientlogin.rs b/src/message/handshake/clientlogin.rs
index dffd996..c589810 100644
--- a/src/message/handshake/clientlogin.rs
+++ b/src/message/handshake/clientlogin.rs
@@ -1,8 +1,7 @@
+use crate::error::ProtocolError;
use crate::primitive::{Variant, VariantMap};
use crate::HandshakeSerialize;
-use failure::Error;
-
/// Login to the core with user data
/// username and password are transmitted in plain text
#[derive(Debug, Clone)]
@@ -12,17 +11,11 @@ pub struct ClientLogin {
}
impl HandshakeSerialize for ClientLogin {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
let mut values: VariantMap = VariantMap::new();
- values.insert(
- "MsgType".to_string(),
- Variant::String("ClientLogin".to_string()),
- );
+ values.insert("MsgType".to_string(), Variant::String("ClientLogin".to_string()));
values.insert("User".to_string(), Variant::String(self.user.clone()));
- values.insert(
- "Password".to_string(),
- Variant::String(self.password.clone()),
- );
+ values.insert("Password".to_string(), Variant::String(self.password.clone()));
return HandshakeSerialize::serialize(&values);
}
}
diff --git a/src/message/handshake/clientloginack.rs b/src/message/handshake/clientloginack.rs
index 72dd6ac..c8650f9 100644
--- a/src/message/handshake/clientloginack.rs
+++ b/src/message/handshake/clientloginack.rs
@@ -2,15 +2,13 @@ use crate::error::ProtocolError;
use crate::primitive::{Variant, VariantMap};
use crate::{HandshakeDeserialize, HandshakeSerialize};
-use failure::Error;
-
/// ClientLoginAck is received after the client has successfully logged in
/// it has no fields
#[derive(Debug, Clone)]
pub struct ClientLoginAck;
impl HandshakeSerialize for ClientLoginAck {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
let mut values: VariantMap = VariantMap::with_capacity(1);
values.insert(
"MsgType".to_string(),
@@ -21,15 +19,15 @@ impl HandshakeSerialize for ClientLoginAck {
}
impl HandshakeDeserialize for ClientLoginAck {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let (len, values): (usize, VariantMap) = HandshakeDeserialize::parse(b)?;
let msgtype = match_variant!(&values["MsgType"], Variant::ByteArray);
if msgtype == "ClientLogin" {
- return Ok((len, Self {}));
+ Ok((len, Self {}))
} else {
- bail!(ProtocolError::WrongMsgType);
+ Err(ProtocolError::WrongMsgType)
}
}
}
diff --git a/src/message/handshake/clientloginreject.rs b/src/message/handshake/clientloginreject.rs
index 0c0fc85..964ce0c 100644
--- a/src/message/handshake/clientloginreject.rs
+++ b/src/message/handshake/clientloginreject.rs
@@ -1,8 +1,7 @@
+use crate::error::ProtocolError;
use crate::primitive::{Variant, VariantMap};
use crate::HandshakeSerialize;
-use failure::Error;
-
/// ClientLoginReject is received after the client failed to login
/// It contains an error message as String
#[derive(Debug, Clone)]
@@ -11,16 +10,13 @@ pub struct ClientLoginReject {
}
impl HandshakeSerialize for ClientLoginReject {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
let mut values: VariantMap = VariantMap::with_capacity(1);
values.insert(
"MsgType".to_string(),
Variant::String("ClientLoginReject".to_string()),
);
- values.insert(
- "ErrorString".to_string(),
- Variant::String(self.error.clone()),
- );
+ values.insert("ErrorString".to_string(), Variant::String(self.error.clone()));
return HandshakeSerialize::serialize(&values);
}
}
diff --git a/src/message/handshake/connack.rs b/src/message/handshake/connack.rs
index a246679..bed0cb5 100644
--- a/src/message/handshake/connack.rs
+++ b/src/message/handshake/connack.rs
@@ -1,4 +1,4 @@
-use failure::Error;
+use crate::error::ProtocolError;
/// Data received right after initializing the connection
///
@@ -30,7 +30,7 @@ impl Default for ConnAck {
}
impl crate::serialize::Serialize for ConnAck {
- fn serialize(&self) -> Result<Vec<std::primitive::u8>, Error> {
+ fn serialize(&self) -> Result<Vec<std::primitive::u8>, ProtocolError> {
let mut bytes: Vec<u8> = Vec::new();
bytes.append(&mut self.flags.serialize()?);
@@ -42,7 +42,7 @@ impl crate::serialize::Serialize for ConnAck {
}
impl crate::deserialize::Deserialize for ConnAck {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let (flen, flags) = u8::parse(b)?;
let (elen, extra) = i16::parse(&b[flen..])?;
let (vlen, version) = i8::parse(&b[(flen + elen)..])?;
diff --git a/src/message/handshake/mod.rs b/src/message/handshake/mod.rs
index 029eb86..186abf0 100644
--- a/src/message/handshake/mod.rs
+++ b/src/message/handshake/mod.rs
@@ -24,6 +24,7 @@ pub use protocol::*;
pub use sessioninit::*;
pub use types::*;
+use crate::error::ProtocolError;
use crate::primitive::VariantMap;
use crate::{HandshakeDeserialize, HandshakeSerialize};
@@ -39,7 +40,7 @@ pub enum HandshakeMessage {
}
impl HandshakeSerialize for HandshakeMessage {
- fn serialize(&self) -> Result<Vec<u8>, failure::Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
match self {
HandshakeMessage::ClientInit(inner) => inner.serialize(),
HandshakeMessage::ClientInitAck(inner) => inner.serialize(),
@@ -53,7 +54,7 @@ impl HandshakeSerialize for HandshakeMessage {
}
impl HandshakeDeserialize for HandshakeMessage {
- fn parse(b: &[u8]) -> Result<(usize, Self), failure::Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let (size, res) = VariantMap::parse(b)?;
let msgtype: String = (&res["MsgType"]).into();
diff --git a/src/message/handshake/sessioninit.rs b/src/message/handshake/sessioninit.rs
index 04f3cff..048324d 100644
--- a/src/message/handshake/sessioninit.rs
+++ b/src/message/handshake/sessioninit.rs
@@ -1,9 +1,8 @@
+use crate::error::ProtocolError;
use crate::message::objects::Identity;
use crate::primitive::{BufferInfo, Variant, VariantMap};
use crate::HandshakeSerialize;
-use failure::Error;
-
/// SessionInit is received along with ClientLoginAck to initialize that user Session
// TODO Replace with proper types
#[derive(Debug, Clone)]
@@ -46,12 +45,9 @@ impl From<VariantMap> for SessionInit {
}
impl HandshakeSerialize for SessionInit {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
let mut values: VariantMap = VariantMap::with_capacity(4);
- values.insert(
- "MsgType".to_string(),
- Variant::String("SessionInit".to_string()),
- );
+ values.insert("MsgType".to_string(), Variant::String("SessionInit".to_string()));
// values.insert(
// "Identities".to_string(),
// Variant::VariantList(
diff --git a/src/message/handshake/types.rs b/src/message/handshake/types.rs
index 6d4960d..fd8c8fa 100644
--- a/src/message/handshake/types.rs
+++ b/src/message/handshake/types.rs
@@ -1,8 +1,6 @@
use std::result::Result;
use std::vec::Vec;
-use failure::Error;
-
use crate::error::ProtocolError;
use crate::primitive::Variant;
use crate::util;
@@ -12,7 +10,7 @@ use crate::message::handshake::{HandshakeDeserialize, HandshakeSerialize};
use crate::primitive::VariantMap;
impl HandshakeSerialize for VariantMap {
- fn serialize<'a>(&'a self) -> Result<Vec<u8>, Error> {
+ fn serialize<'a>(&'a self) -> Result<Vec<u8>, ProtocolError> {
let mut res: Vec<u8> = Vec::new();
for (k, v) in self {
@@ -29,7 +27,7 @@ impl HandshakeSerialize for VariantMap {
}
impl HandshakeDeserialize for VariantMap {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let (_, len) = i32::parse(&b[0..4])?;
let mut pos: usize = 4;
@@ -45,7 +43,7 @@ impl HandshakeDeserialize for VariantMap {
match name {
Variant::String(x) => map.insert(x, value),
Variant::ByteArray(x) => map.insert(x, value),
- _ => bail!(ProtocolError::WrongVariant),
+ _ => return Err(ProtocolError::WrongVariant),
};
}
@@ -58,21 +56,18 @@ 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,
+ 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
- );
+ 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,
+ 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));
@@ -86,8 +81,8 @@ pub fn deserialize_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,
+ 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));
diff --git a/src/message/signalproxy/heartbeat.rs b/src/message/signalproxy/heartbeat.rs
index 58dc430..32df3d4 100644
--- a/src/message/signalproxy/heartbeat.rs
+++ b/src/message/signalproxy/heartbeat.rs
@@ -1,3 +1,4 @@
+use crate::error::ProtocolError;
use crate::message::MessageType;
use crate::primitive::{DateTime, Variant, VariantList};
use crate::{deserialize::Deserialize, serialize::Serialize};
@@ -8,7 +9,7 @@ pub struct HeartBeat {
}
impl Serialize for HeartBeat {
- fn serialize(&self) -> Result<Vec<std::primitive::u8>, failure::Error> {
+ fn serialize(&self) -> Result<Vec<std::primitive::u8>, ProtocolError> {
let mut res = VariantList::new();
res.push(Variant::i32(MessageType::HeartBeat as i32));
@@ -19,7 +20,7 @@ impl Serialize for HeartBeat {
}
impl Deserialize for HeartBeat {
- fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), failure::Error> {
+ fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), ProtocolError> {
let (size, mut res) = VariantList::parse(&b)?;
res.remove(0);
@@ -39,7 +40,7 @@ pub struct HeartBeatReply {
}
impl Serialize for HeartBeatReply {
- fn serialize(&self) -> Result<Vec<std::primitive::u8>, failure::Error> {
+ fn serialize(&self) -> Result<Vec<std::primitive::u8>, ProtocolError> {
let mut res = VariantList::new();
res.push(Variant::i32(MessageType::HeartBeatReply as i32));
@@ -50,7 +51,7 @@ impl Serialize for HeartBeatReply {
}
impl Deserialize for HeartBeatReply {
- fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), failure::Error> {
+ fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), ProtocolError> {
let (size, mut res) = VariantList::parse(&b)?;
res.remove(0);
diff --git a/src/message/signalproxy/initdata.rs b/src/message/signalproxy/initdata.rs
index a391b4a..2b9fa18 100644
--- a/src/message/signalproxy/initdata.rs
+++ b/src/message/signalproxy/initdata.rs
@@ -1,3 +1,4 @@
+use crate::error::ProtocolError;
use crate::message::MessageType;
use crate::primitive::{Variant, VariantList};
use crate::{deserialize::Deserialize, serialize::Serialize};
@@ -12,7 +13,7 @@ pub struct InitData {
}
impl Serialize for InitData {
- fn serialize(&self) -> Result<Vec<std::primitive::u8>, failure::Error> {
+ fn serialize(&self) -> Result<Vec<std::primitive::u8>, ProtocolError> {
let mut res = VariantList::new();
res.push(Variant::i32(MessageType::InitData as i32));
@@ -26,7 +27,7 @@ impl Serialize for InitData {
}
impl Deserialize for InitData {
- fn parse(b: &[u8]) -> Result<(usize, Self), failure::Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let (size, mut res) = VariantList::parse(&b)?;
res.remove(0);
diff --git a/src/message/signalproxy/initrequest.rs b/src/message/signalproxy/initrequest.rs
index 1beef5c..79b6cbc 100644
--- a/src/message/signalproxy/initrequest.rs
+++ b/src/message/signalproxy/initrequest.rs
@@ -1,3 +1,4 @@
+use crate::error::ProtocolError;
use crate::message::MessageType;
use crate::primitive::{Variant, VariantList};
use crate::{deserialize::Deserialize, serialize::Serialize};
@@ -9,7 +10,7 @@ pub struct InitRequest {
}
impl Serialize for InitRequest {
- fn serialize(&self) -> Result<Vec<std::primitive::u8>, failure::Error> {
+ fn serialize(&self) -> Result<Vec<std::primitive::u8>, ProtocolError> {
let mut res = VariantList::new();
res.push(Variant::i32(MessageType::InitRequest as i32));
@@ -21,7 +22,7 @@ impl Serialize for InitRequest {
}
impl Deserialize for InitRequest {
- fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), failure::Error> {
+ fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), ProtocolError> {
let (size, mut res) = VariantList::parse(&b)?;
res.remove(0);
diff --git a/src/message/signalproxy/mod.rs b/src/message/signalproxy/mod.rs
index cc1fc54..5801846 100644
--- a/src/message/signalproxy/mod.rs
+++ b/src/message/signalproxy/mod.rs
@@ -1,5 +1,6 @@
use crate::{
deserialize::Deserialize,
+ error::ProtocolError,
primitive::{Variant, VariantList},
serialize::Serialize,
};
@@ -57,13 +58,7 @@ impl SyncProxy {
}
/// Send a SyncMessage
- fn sync(
- &self,
- class_name: Class,
- object_name: Option<&str>,
- function: &str,
- params: VariantList,
- ) {
+ fn sync(&self, class_name: Class, object_name: Option<&str>, function: &str, params: VariantList) {
let msg = SyncMessage {
class_name,
object_name: object_name.unwrap_or("").to_string(),
@@ -91,12 +86,10 @@ pub trait Syncable {
/// Send a SyncMessage.
fn send_sync(&self, function: &str, params: VariantList) {
- crate::message::signalproxy::SYNC_PROXY.get().unwrap().sync(
- Self::CLASS,
- None,
- function,
- params,
- );
+ crate::message::signalproxy::SYNC_PROXY
+ .get()
+ .unwrap()
+ .sync(Self::CLASS, None, function, params);
}
/// Send a RpcCall
@@ -125,10 +118,9 @@ where
Self: Sized,
{
match msg.slot_name.as_str() {
- "requestUpdate" => StatefulSyncableServer::request_update(
- self,
- msg.params.pop().unwrap().try_into().unwrap(),
- ),
+ "requestUpdate" => {
+ StatefulSyncableServer::request_update(self, msg.params.pop().unwrap().try_into().unwrap())
+ }
_ => StatefulSyncableServer::sync_custom(self, msg),
}
}
@@ -167,9 +159,7 @@ pub trait StatefulSyncableClient: Syncable + translation::NetworkMap {
Self: Sized,
{
match msg.slot_name.as_str() {
- "update" => {
- StatefulSyncableClient::update(self, msg.params.pop().unwrap().try_into().unwrap())
- }
+ "update" => StatefulSyncableClient::update(self, msg.params.pop().unwrap().try_into().unwrap()),
_ => StatefulSyncableClient::sync_custom(self, msg),
}
}
@@ -229,7 +219,7 @@ pub enum Message {
// }
impl Serialize for Message {
- fn serialize(&self) -> Result<Vec<std::primitive::u8>, failure::Error> {
+ fn serialize(&self) -> Result<Vec<std::primitive::u8>, ProtocolError> {
match &self {
Message::SyncMessage(value) => value.serialize(),
Message::RpcCall(value) => value.serialize(),
@@ -242,7 +232,7 @@ impl Serialize for Message {
}
impl Deserialize for Message {
- fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), failure::Error> {
+ fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), ProtocolError> {
let (_, message_type) = i32::parse(&b[9..13])?;
match MessageType::from(message_type) {
diff --git a/src/message/signalproxy/objects/backlogmanager.rs b/src/message/signalproxy/objects/backlogmanager.rs
index 7d6624d..4e74b15 100644
--- a/src/message/signalproxy/objects/backlogmanager.rs
+++ b/src/message/signalproxy/objects/backlogmanager.rs
@@ -48,6 +48,8 @@
// receiveBacklogAllFiltered(first: MsgId, last: MsgId, limit: Int, additional: Int, type: Int, flags: Int, messages: QVariantList)
// }
+#![allow(non_snake_case, dead_code)]
+
use crate::primitive::VariantList;
/// Receive and Request Backlog
@@ -59,14 +61,7 @@ impl BacklogManager {
/// Loads backlog for `bufferId`, starting at message `first`, up to `last`
/// (plus `additional` more messages after `last`) but at most `limit`
/// messages total.
- fn requestBacklog(
- self: Self,
- buffer_id: u32,
- first: u32,
- last: u32,
- limit: u32,
- additional: u32,
- ) {
+ fn requestBacklog(self: Self, buffer_id: u32, first: u32, last: u32, limit: u32, additional: u32) {
unimplemented!()
}
diff --git a/src/message/signalproxy/rpccall.rs b/src/message/signalproxy/rpccall.rs
index e485f6b..04c75cb 100644
--- a/src/message/signalproxy/rpccall.rs
+++ b/src/message/signalproxy/rpccall.rs
@@ -1,3 +1,4 @@
+use crate::error::ProtocolError;
use crate::message::MessageType;
use crate::primitive::Message;
use crate::primitive::{Variant, VariantList};
@@ -21,7 +22,7 @@ pub struct DisplayMessage {
// }
impl Serialize for RpcCall {
- fn serialize(&self) -> Result<Vec<std::primitive::u8>, failure::Error> {
+ fn serialize(&self) -> Result<Vec<std::primitive::u8>, ProtocolError> {
let mut res = VariantList::new();
res.push(Variant::i32(MessageType::RpcCall as i32));
@@ -39,7 +40,7 @@ impl Serialize for RpcCall {
}
impl Deserialize for RpcCall {
- fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), failure::Error> {
+ fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), ProtocolError> {
let (size, mut res) = VariantList::parse(&b)?;
res.remove(0);
diff --git a/src/message/signalproxy/syncmessage.rs b/src/message/signalproxy/syncmessage.rs
index 7e7aabc..d1f359b 100644
--- a/src/message/signalproxy/syncmessage.rs
+++ b/src/message/signalproxy/syncmessage.rs
@@ -1,3 +1,4 @@
+use crate::error::ProtocolError;
use crate::message::MessageType;
use crate::primitive::{Variant, VariantList};
use crate::{deserialize::Deserialize, serialize::Serialize};
@@ -85,7 +86,7 @@ pub struct SyncMessage {
// impl Act for SyncMessage {}
impl Serialize for SyncMessage {
- fn serialize(&self) -> Result<Vec<std::primitive::u8>, failure::Error> {
+ fn serialize(&self) -> Result<Vec<std::primitive::u8>, ProtocolError> {
let mut res = VariantList::new();
res.push(Variant::i32(MessageType::SyncMessage as i32));
@@ -100,7 +101,7 @@ impl Serialize for SyncMessage {
}
impl Deserialize for SyncMessage {
- fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), failure::Error> {
+ fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), ProtocolError> {
let (size, mut res) = VariantList::parse(&b)?;
res.remove(0);
diff --git a/src/primitive/bufferinfo.rs b/src/primitive/bufferinfo.rs
index 97d9408..a87c418 100644
--- a/src/primitive/bufferinfo.rs
+++ b/src/primitive/bufferinfo.rs
@@ -1,8 +1,6 @@
use std::vec::Vec;
-use failure::Error;
-
-use crate::{deserialize::*, serialize::*};
+use crate::{deserialize::*, error::ProtocolError, serialize::*};
/// The BufferInfo struct represents a BufferInfo as received in IRC
///
@@ -20,7 +18,7 @@ pub struct BufferInfo {
}
impl Serialize for BufferInfo {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
let mut values: Vec<u8> = Vec::new();
values.append(&mut i32::serialize(&self.id)?);
@@ -34,7 +32,7 @@ impl Serialize for BufferInfo {
}
impl Deserialize for BufferInfo {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let (_, id) = i32::parse(&b[0..4])?;
let (_, network_id) = i32::parse(&b[4..8])?;
let (_, buffer_type) = i16::parse(&b[8..10])?;
diff --git a/src/primitive/datetime.rs b/src/primitive/datetime.rs
index 395830d..303716a 100644
--- a/src/primitive/datetime.rs
+++ b/src/primitive/datetime.rs
@@ -1,4 +1,4 @@
-use crate::{deserialize::*, serialize::*};
+use crate::{deserialize::*, error::ProtocolError, serialize::*};
use time::{OffsetDateTime, PrimitiveDateTime, UtcOffset};
@@ -43,7 +43,7 @@ impl From<i8> for TimeSpec {
}
impl Serialize for OffsetDateTime {
- fn serialize(&self) -> Result<Vec<u8>, failure::Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
let mut values: Vec<u8> = Vec::new();
values.extend(i32::serialize(&(self.date().to_julian_day() as i32))?);
@@ -66,7 +66,7 @@ impl Serialize for OffsetDateTime {
}
impl Deserialize for OffsetDateTime {
- fn parse(b: &[u8]) -> Result<(usize, Self), failure::Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let (_, julian_day) = i32::parse(&b[0..4])?;
let (_, millis_of_day) = i32::parse(&b[4..8])?;
let (_, zone) = u8::parse(&b[8..9])?;
@@ -112,7 +112,7 @@ impl Deserialize for OffsetDateTime {
}
impl Serialize for Date {
- fn serialize(&self) -> Result<Vec<std::primitive::u8>, failure::Error> {
+ fn serialize(&self) -> Result<Vec<std::primitive::u8>, ProtocolError> {
let mut values: Vec<u8> = Vec::new();
values.extend(i32::serialize(&(self.to_julian_day() as i32))?);
@@ -122,7 +122,7 @@ impl Serialize for Date {
}
impl Deserialize for Date {
- fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), failure::Error> {
+ fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), ProtocolError> {
let (_, julian_day) = i32::parse(&b[0..4])?;
let date = Date::from_julian_day(julian_day)?;
@@ -131,7 +131,7 @@ impl Deserialize for Date {
}
impl Serialize for Time {
- fn serialize(&self) -> Result<Vec<std::primitive::u8>, failure::Error> {
+ fn serialize(&self) -> Result<Vec<std::primitive::u8>, ProtocolError> {
let mut values: Vec<u8> = Vec::new();
let time: i32 = {
@@ -150,7 +150,7 @@ impl Serialize for Time {
}
impl Deserialize for Time {
- fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), failure::Error> {
+ fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), ProtocolError> {
let (_, millis_of_day) = i32::parse(&b[0..4])?;
let hour = millis_of_day / 60 / 60000;
diff --git a/src/primitive/message.rs b/src/primitive/message.rs
index 27d60f5..eebce72 100644
--- a/src/primitive/message.rs
+++ b/src/primitive/message.rs
@@ -1,7 +1,6 @@
use std::{collections::HashMap, vec::Vec};
-use failure::Error;
-
+use crate::error::ProtocolError;
use crate::{deserialize::*, serialize::*};
use crate::primitive::BufferInfo;
@@ -55,7 +54,7 @@ pub struct Message {
}
impl Serialize for Message {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
let mut values: Vec<u8> = Vec::new();
#[cfg(feature = "long-message-id")]
@@ -89,7 +88,7 @@ impl Serialize for Message {
}
impl Deserialize for Message {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let mut pos = 0;
#[cfg(feature = "long-message-id")]
let (parsed, msg_id) = i64::parse(&b[pos..])?;
@@ -289,13 +288,12 @@ mod tests {
assert_eq!(
message.serialize().unwrap(),
[
- 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 95, 244, 79, 69, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0,
- 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 5, 35, 116, 101, 115, 116, 0, 0, 0, 4, 116,
- 101, 115, 116, 0, 0, 0, 6, 98, 108, 97, 98, 108, 97, 0, 0, 0, 9, 116, 101, 115,
- 116, 32, 117, 115, 101, 114, 0, 0, 0, 28, 104, 116, 116, 112, 115, 58, 47, 47, 106,
- 102, 107, 97, 108, 115, 100, 107, 106, 102, 106, 46, 99, 111, 109, 47, 107, 106,
- 107, 106, 0, 0, 0, 22, 116, 104, 105, 115, 32, 105, 115, 32, 97, 32, 116, 101, 115,
- 116, 32, 109, 101, 115, 115, 97, 103, 101
+ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 95, 244, 79, 69, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1,
+ 0, 2, 0, 0, 0, 0, 0, 0, 0, 5, 35, 116, 101, 115, 116, 0, 0, 0, 4, 116, 101, 115, 116, 0, 0,
+ 0, 6, 98, 108, 97, 98, 108, 97, 0, 0, 0, 9, 116, 101, 115, 116, 32, 117, 115, 101, 114, 0, 0,
+ 0, 28, 104, 116, 116, 112, 115, 58, 47, 47, 106, 102, 107, 97, 108, 115, 100, 107, 106, 102,
+ 106, 46, 99, 111, 109, 47, 107, 106, 107, 106, 0, 0, 0, 22, 116, 104, 105, 115, 32, 105, 115,
+ 32, 97, 32, 116, 101, 115, 116, 32, 109, 101, 115, 115, 97, 103, 101
]
)
}
@@ -321,13 +319,12 @@ mod tests {
};
let bytes = vec![
- 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 95, 244, 79, 69, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
- 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 5, 35, 116, 101, 115, 116, 0, 0, 0, 4, 116, 101, 115,
- 116, 0, 0, 0, 6, 98, 108, 97, 98, 108, 97, 0, 0, 0, 9, 116, 101, 115, 116, 32, 117,
- 115, 101, 114, 0, 0, 0, 28, 104, 116, 116, 112, 115, 58, 47, 47, 106, 102, 107, 97,
- 108, 115, 100, 107, 106, 102, 106, 46, 99, 111, 109, 47, 107, 106, 107, 106, 0, 0, 0,
- 22, 116, 104, 105, 115, 32, 105, 115, 32, 97, 32, 116, 101, 115, 116, 32, 109, 101,
- 115, 115, 97, 103, 101,
+ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 95, 244, 79, 69, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2,
+ 0, 0, 0, 0, 0, 0, 0, 5, 35, 116, 101, 115, 116, 0, 0, 0, 4, 116, 101, 115, 116, 0, 0, 0, 6, 98,
+ 108, 97, 98, 108, 97, 0, 0, 0, 9, 116, 101, 115, 116, 32, 117, 115, 101, 114, 0, 0, 0, 28, 104,
+ 116, 116, 112, 115, 58, 47, 47, 106, 102, 107, 97, 108, 115, 100, 107, 106, 102, 106, 46, 99,
+ 111, 109, 47, 107, 106, 107, 106, 0, 0, 0, 22, 116, 104, 105, 115, 32, 105, 115, 32, 97, 32, 116,
+ 101, 115, 116, 32, 109, 101, 115, 115, 97, 103, 101,
];
assert_eq!(Message::parse(&bytes).unwrap(), (133, message))
diff --git a/src/primitive/signedint.rs b/src/primitive/signedint.rs
index 2d2029d..b139685 100644
--- a/src/primitive/signedint.rs
+++ b/src/primitive/signedint.rs
@@ -4,57 +4,55 @@ use std::io::Cursor;
use std::result::Result;
use std::vec::Vec;
-use failure::Error;
-
-use crate::{deserialize::*, serialize::*};
+use crate::{deserialize::*, error::ProtocolError, serialize::*};
impl Serialize for i64 {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
Ok(Vec::from(self.to_be_bytes()))
}
}
impl Deserialize for i64 {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let mut rdr = Cursor::new(&b[0..8]);
return Ok((8, rdr.read_i64::<BigEndian>()?));
}
}
impl Serialize for i32 {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
Ok(Vec::from(self.to_be_bytes()))
}
}
impl Deserialize for i32 {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let mut rdr = Cursor::new(&b[0..4]);
return Ok((4, rdr.read_i32::<BigEndian>()?));
}
}
impl Serialize for i16 {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
Ok(Vec::from(self.to_be_bytes()))
}
}
impl Deserialize for i16 {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let mut rdr = Cursor::new(&b[0..2]);
return Ok((2, rdr.read_i16::<BigEndian>()?));
}
}
impl Serialize for i8 {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
Ok(Vec::from(self.to_be_bytes()))
}
}
impl Deserialize for i8 {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let mut rdr = Cursor::new(&b[0..1]);
return Ok((1, rdr.read_i8()?));
}
diff --git a/src/primitive/string.rs b/src/primitive/string.rs
index 5addff2..30bdffa 100644
--- a/src/primitive/string.rs
+++ b/src/primitive/string.rs
@@ -3,14 +3,12 @@ extern crate byteorder;
use std::result::Result;
use std::vec::Vec;
-use failure::Error;
-
use log::trace;
use crate::{deserialize::*, error::ProtocolError, serialize::*, util};
impl Deserialize for char {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let (slen, qchar): (usize, u16) = u16::parse(&b[0..2])?;
let qchar = char::from_u32(qchar as u32).ok_or(ProtocolError::CharError)?;
@@ -19,7 +17,7 @@ impl Deserialize for char {
}
impl Serialize for char {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
let mut b = [0, 0];
self.encode_utf16(&mut b);
@@ -33,7 +31,7 @@ impl Serialize for char {
///
/// Strings can only be serialized as UTF-8 null-terminated ByteArrays with (de)serialize_utf8().
impl Serialize for String {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
let mut res: Vec<u8> = Vec::new();
self.encode_utf16()
@@ -45,7 +43,7 @@ impl Serialize for String {
}
impl SerializeUTF8 for String {
- fn serialize_utf8(&self) -> Result<Vec<u8>, Error> {
+ fn serialize_utf8(&self) -> Result<Vec<u8>, ProtocolError> {
let mut res: Vec<u8> = Vec::new();
res.extend(self.clone().into_bytes());
util::prepend_byte_len(&mut res);
@@ -54,7 +52,7 @@ impl SerializeUTF8 for String {
}
impl Deserialize for String {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
// Parse Length
let (_, len) = i32::parse(&b[0..4])?;
trace!(target: "primitive::String", "Parsing with length: {:?}, from bytes: {:x?}", len, &b[0..4]);
@@ -85,7 +83,7 @@ impl Deserialize for String {
}
impl DeserializeUTF8 for String {
- fn parse_utf8(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse_utf8(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let (_, len) = i32::parse(&b[0..4])?;
trace!(target: "primitive::String", "Parsing with length: {:?}, from bytes: {:x?}", len, &b[0..4]);
@@ -119,10 +117,7 @@ pub fn string_serialize() {
assert_eq!(
test_string.serialize().unwrap(),
- [
- 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, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, 117, 0, 114, 0, 101, 0, 100]
);
}
@@ -139,8 +134,8 @@ pub fn string_serialize_utf8() {
#[test]
pub fn string_deserialize() {
let test_bytes: &[u8] = &[
- 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, 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,
];
let (len, res) = String::parse(test_bytes).unwrap();
assert_eq!(res, "Configured");
diff --git a/src/primitive/stringlist.rs b/src/primitive/stringlist.rs
index 434f2f2..872f5be 100644
--- a/src/primitive/stringlist.rs
+++ b/src/primitive/stringlist.rs
@@ -3,11 +3,9 @@ extern crate byteorder;
use std::result::Result;
use std::vec::Vec;
-use failure::Error;
-
use log::trace;
-use crate::{deserialize::*, serialize::*};
+use crate::{deserialize::*, error::ProtocolError, serialize::*};
/// StringList are represented as a Vec of Strings
///
@@ -15,7 +13,7 @@ use crate::{deserialize::*, serialize::*};
pub type StringList = Vec<String>;
impl Serialize for StringList {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
let len: i32 = self.len().try_into()?;
let mut res: Vec<u8> = Vec::new();
@@ -29,7 +27,7 @@ impl Serialize for StringList {
}
impl Deserialize for StringList {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let (_, len) = i32::parse(&b[0..4])?;
trace!(target: "primitive::StringList", "Parsing with length: {:?}, from bytes: {:x?}", len, &b[0..4]);
let mut res: StringList = StringList::new();
@@ -54,8 +52,8 @@ pub fn string_list_serialize() {
assert_eq!(
test_list.serialize().unwrap(),
[
- 0, 0, 0, 1, 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, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, 117, 0, 114, 0, 101,
+ 0, 100
]
)
}
@@ -63,8 +61,8 @@ pub fn string_list_serialize() {
#[test]
pub fn string_list_deserialize() {
let test_bytes: &[u8] = &[
- 0, 0, 0, 1, 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, 0, 0, 1, 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,
];
let mut test_list = StringList::new();
test_list.push("Configured".to_string());
diff --git a/src/primitive/unsignedint.rs b/src/primitive/unsignedint.rs
index 90ec696..b5d76cd 100644
--- a/src/primitive/unsignedint.rs
+++ b/src/primitive/unsignedint.rs
@@ -5,77 +5,77 @@ use std::io::Cursor;
use std::result::Result;
use std::vec::Vec;
-use failure::Error;
-
use crate::error::ProtocolError;
use crate::{deserialize::*, serialize::*};
impl Serialize for bool {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
Ok({
let i = *self as i8;
Vec::from(i.to_be_bytes())
})
}
}
+
impl Deserialize for bool {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
if b[0] == 0 {
- return Ok((1, false));
+ Ok((1, false))
} else if b[0] == 1 {
- return Ok((1, true));
+ Ok((1, true))
} else {
- bail!(ProtocolError::BoolOutOfRange);
- };
+ Err(ProtocolError::BoolOutOfRange)
+ }
}
}
+
impl Serialize for u64 {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
Ok(Vec::from(self.to_be_bytes()))
}
}
impl Deserialize for u64 {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let mut rdr = Cursor::new(&b[0..8]);
return Ok((8, rdr.read_u64::<BigEndian>()?));
}
}
impl Serialize for u32 {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
Ok(Vec::from(self.to_be_bytes()))
}
}
impl Deserialize for u32 {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let mut rdr = Cursor::new(&b[0..4]);
return Ok((4, rdr.read_u32::<BigEndian>()?));
}
}
impl Serialize for u16 {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
Ok(Vec::from(self.to_be_bytes()))
}
}
impl Deserialize for u16 {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let mut rdr = Cursor::new(&b[0..2]);
return Ok((2, rdr.read_u16::<BigEndian>()?));
}
}
impl Serialize for u8 {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
Ok(Vec::from(self.to_be_bytes()))
}
}
impl Deserialize for u8 {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
return Ok((1, b[0]));
}
}
diff --git a/src/primitive/variant.rs b/src/primitive/variant.rs
index 46334a0..e84e5c0 100644
--- a/src/primitive/variant.rs
+++ b/src/primitive/variant.rs
@@ -1,7 +1,5 @@
use std::{collections::HashMap, vec::Vec};
-use failure::Error;
-
use itertools::Itertools;
use log::{error, trace};
@@ -155,13 +153,13 @@ where
}
impl Serialize for Variant {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
let unknown: u8 = 0x00;
let mut res: Vec<u8> = Vec::new();
match self {
Variant::Unknown => {
- bail!(ProtocolError::UnknownVariant);
+ return Err(ProtocolError::UnknownVariant);
}
Variant::VariantMap(v) => {
res.extend(primitive::QVARIANTMAP.to_be_bytes().iter());
@@ -277,7 +275,7 @@ impl Serialize for Variant {
}
impl Deserialize for Variant {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
trace!("trying to parse variant with bytes: {:?}", b);
let (_, qtype) = i32::parse(&b[0..4])?;
let qtype = qtype as u32;
@@ -426,7 +424,7 @@ impl Deserialize for Variant {
}
err => {
error!(target: "parser", "UnknownVariant: {:x?}", err);
- bail!(ProtocolError::UnknownVariant);
+ return Err(ProtocolError::UnknownVariant);
}
}
}
diff --git a/src/primitive/variantlist.rs b/src/primitive/variantlist.rs
index d3518e6..58286e3 100644
--- a/src/primitive/variantlist.rs
+++ b/src/primitive/variantlist.rs
@@ -1,9 +1,8 @@
use std::vec::Vec;
-use failure::Error;
-
use log::trace;
+use crate::error::ProtocolError;
use crate::{deserialize::*, serialize::*};
use crate::primitive::Variant;
@@ -14,7 +13,7 @@ use crate::primitive::Variant;
pub type VariantList = Vec<Variant>;
impl Serialize for VariantList {
- fn serialize(&self) -> Result<Vec<u8>, Error> {
+ fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
let len: i32 = self.len().try_into()?;
let mut res: Vec<u8> = Vec::new();
@@ -28,7 +27,7 @@ impl Serialize for VariantList {
}
impl Deserialize for VariantList {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let (_, len) = i32::parse(&b[0..4])?;
trace!(target: "primitive::VariantList", "Parsing VariantList with {:?} elements", len);
diff --git a/src/primitive/variantmap.rs b/src/primitive/variantmap.rs
index 1eeb006..3cb30cc 100644
--- a/src/primitive/variantmap.rs
+++ b/src/primitive/variantmap.rs
@@ -1,10 +1,9 @@
use std::collections::HashMap;
use std::vec::Vec;
-use failure::Error;
-
use log::trace;
+use crate::error::ProtocolError;
use crate::{deserialize::*, serialize::*};
use crate::primitive::Variant;
@@ -16,7 +15,7 @@ use crate::util;
pub type VariantMap = HashMap<String, Variant>;
impl Serialize for VariantMap {
- fn serialize<'a>(&'a self) -> Result<Vec<u8>, Error> {
+ fn serialize<'a>(&'a self) -> Result<Vec<u8>, ProtocolError> {
let mut res: Vec<u8> = Vec::new();
for (k, v) in self {
@@ -32,7 +31,7 @@ impl Serialize for VariantMap {
}
impl Deserialize for VariantMap {
- fn parse(b: &[u8]) -> Result<(usize, Self), Error> {
+ fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
let (_, len) = i32::parse(&b[0..4])?;
trace!(target: "primitive::VariantMap", "Parsing VariantMap with {:?} elements", len);