From b1bae553b620f0a1d71c6be7fa98c10978662907 Mon Sep 17 00:00:00 2001 From: Max Audron Date: Tue, 21 Jan 2020 16:12:13 +0100 Subject: le tokio --- src/protocol/message/handshake/types.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/protocol/message/handshake') diff --git a/src/protocol/message/handshake/types.rs b/src/protocol/message/handshake/types.rs index 3c5d019..643b376 100644 --- a/src/protocol/message/handshake/types.rs +++ b/src/protocol/message/handshake/types.rs @@ -4,29 +4,31 @@ use std::result::Result; use std::convert::TryInto; use std::collections::HashMap; +use failure::Error; + use crate::util; use crate::protocol::primitive::{String, Variant}; use crate::protocol::primitive::serialize::Serialize; use crate::protocol::primitive::deserialize::Deserialize; use crate::protocol::primitive::qread::QRead; -use crate::protocol::error::ErrorKind; +use crate::protocol::error::ProtocolError; pub trait HandshakeSerialize { - fn serialize(&self) -> Result, ErrorKind>; + fn serialize(&self) -> Result, Error>; } pub trait HandshakeDeserialize { - fn parse(b: &[u8]) -> Result<(usize, Self), ErrorKind> where Self: std::marker::Sized ; + fn parse(b: &[u8]) -> Result<(usize, Self), Error> where Self: std::marker::Sized ; } pub trait HandshakeQRead { - fn read(stream: &mut T, buf: &mut [u8]) -> Result; + fn read(stream: &mut T, buf: &mut [u8]) -> Result; } pub type VariantMap = HashMap; impl HandshakeSerialize for VariantMap { - fn serialize<'a>(&'a self) -> Result, ErrorKind> { + fn serialize<'a>(&'a self) -> Result, Error> { let mut res: Vec = Vec::new(); for (k, v) in self { @@ -37,7 +39,7 @@ impl HandshakeSerialize for VariantMap { util::insert_bytes(0, &mut res, &mut [0, 0, 0, 10]); - let len: i32 = res.len().try_into()?; + let len: i32 = res.len().try_into().unwrap(); util::insert_bytes(0, &mut res, &mut ((len).to_be_bytes())); return Ok(res); @@ -45,7 +47,7 @@ impl HandshakeSerialize for VariantMap { } impl HandshakeDeserialize for VariantMap { - fn parse(b: &[u8]) -> Result<(usize, Self), ErrorKind> { + fn parse(b: &[u8]) -> Result<(usize, Self), Error> { let (_, len) = i32::parse(&b[0..4])?; let mut pos: usize = 8; @@ -62,7 +64,7 @@ impl HandshakeDeserialize for VariantMap { match name { Variant::String(x) => map.insert(x, value), Variant::StringUTF8(x) => map.insert(x, value), - _ => return Err(ErrorKind::WrongVariant) + _ => bail!(ProtocolError::WrongVariant) }; } @@ -71,7 +73,7 @@ impl HandshakeDeserialize for VariantMap { } impl HandshakeQRead for VariantMap { - fn read(s: &mut T, b: &mut [u8]) -> Result { + fn read(s: &mut T, b: &mut [u8]) -> Result { s.read(&mut b[0..4])?; let (_, len) = i32::parse(&b[0..4])?; let ulen = len as usize; -- cgit v1.2.3