aboutsummaryrefslogtreecommitdiff
path: root/src/primitive
diff options
context:
space:
mode:
Diffstat (limited to 'src/primitive')
-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
10 files changed, 76 insertions, 94 deletions
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);