aboutsummaryrefslogtreecommitdiff
path: root/src/primitive
diff options
context:
space:
mode:
Diffstat (limited to 'src/primitive')
-rw-r--r--src/primitive/bufferid.rs8
-rw-r--r--src/primitive/message.rs10
-rw-r--r--src/primitive/peerptr.rs2
-rw-r--r--src/primitive/string.rs2
-rw-r--r--src/primitive/variant.rs8
5 files changed, 15 insertions, 15 deletions
diff --git a/src/primitive/bufferid.rs b/src/primitive/bufferid.rs
index 9d780c6..88b56fa 100644
--- a/src/primitive/bufferid.rs
+++ b/src/primitive/bufferid.rs
@@ -48,12 +48,12 @@ impl UserType for BufferId {
// TODO this is not correct usage, it's technically not really network repr were converting from
// but just the conversion of VariantList -> Self directly
impl NetworkList for Vec<BufferId> {
- fn to_network_list(&self) -> super::VariantList {
- self.iter().map(|b| Variant::BufferId(*b)).collect()
+ fn to_network_list(&self) -> Result<super::VariantList, ProtocolError> {
+ Ok(self.iter().map(|b| Variant::BufferId(*b)).collect())
}
- fn from_network_list(input: &mut super::VariantList) -> Self {
- input.iter().map(|b| b.try_into().unwrap()).collect()
+ fn from_network_list(input: &mut super::VariantList) -> Result<Self, ProtocolError> {
+ input.iter().map(|b| b.try_into()).collect()
}
}
diff --git a/src/primitive/message.rs b/src/primitive/message.rs
index e558570..819ddd1 100644
--- a/src/primitive/message.rs
+++ b/src/primitive/message.rs
@@ -143,7 +143,7 @@ impl Deserialize for Message {
Self {
msg_id,
timestamp,
- msg_type: MessageType::from_bits(msg_type).unwrap(),
+ msg_type: MessageType::from_bits(msg_type).ok_or(ProtocolError::UnknownMsgType)?,
flags,
buffer,
sender,
@@ -195,7 +195,7 @@ impl<T> crate::message::NetworkList for HashMap<T, MessageType>
where
T: std::convert::TryFrom<Variant> + Into<Variant> + Clone + std::hash::Hash + std::cmp::Eq,
{
- fn to_network_list(&self) -> VariantList {
+ fn to_network_list(&self) -> Result<VariantList, ProtocolError> {
let mut res = Vec::with_capacity(self.len() * 2);
self.iter().for_each(|(k, v)| {
@@ -203,10 +203,10 @@ where
res.push((*v).clone().bits().into());
});
- res
+ Ok(res)
}
- fn from_network_list(input: &mut VariantList) -> Self {
+ fn from_network_list(input: &mut VariantList) -> Result<Self, ProtocolError> {
use itertools::Itertools;
let mut res = HashMap::with_capacity(input.len() / 2);
@@ -224,7 +224,7 @@ where
);
});
- res
+ Ok(res)
}
}
diff --git a/src/primitive/peerptr.rs b/src/primitive/peerptr.rs
index f5fc042..dc4f676 100644
--- a/src/primitive/peerptr.rs
+++ b/src/primitive/peerptr.rs
@@ -40,7 +40,7 @@ mod tests {
// let test_bytes: &[u8] = &[
// 0, 0, 0, 7, 80, 101, 101, 114, 80, 116, 114, 0, 0, 0, 0, 0, 0, 0, 1,
// ];
- // let (len, res) = PeerPtr::parse(test_bytes).unwrap();
+ // let (len, res) = PeerPtr::parse(test_bytes)?;
// assert_eq!(len, test_bytes.len());
// assert_eq!(res, PeerPtr(1));
// }
diff --git a/src/primitive/string.rs b/src/primitive/string.rs
index 0d3e344..31492ae 100644
--- a/src/primitive/string.rs
+++ b/src/primitive/string.rs
@@ -99,7 +99,7 @@ impl Deserialize for String {
pos += slen;
}
- let res: String = String::from_utf16(&chars).unwrap();
+ let res: String = String::from_utf16(&chars)?;
trace!("parsed string: {}", res);
Ok((pos, res))
}
diff --git a/src/primitive/variant.rs b/src/primitive/variant.rs
index f39d405..b201b46 100644
--- a/src/primitive/variant.rs
+++ b/src/primitive/variant.rs
@@ -92,7 +92,7 @@ where
T: std::convert::TryFrom<Variant> + Into<Variant> + Clone + std::hash::Hash + std::cmp::Eq,
S: std::convert::TryFrom<Variant> + Into<Variant> + Clone + std::hash::Hash + std::cmp::Eq,
{
- fn to_network_list(&self) -> VariantList {
+ fn to_network_list(&self) -> Result<VariantList, ProtocolError> {
let mut res = Vec::with_capacity(self.len() * 2);
self.iter().for_each(|(k, v)| {
@@ -100,10 +100,10 @@ where
res.push((*v).clone().into());
});
- res
+ Ok(res)
}
- fn from_network_list(input: &mut VariantList) -> Self {
+ fn from_network_list(input: &mut VariantList) -> Result<Self, ProtocolError> {
let mut res = HashMap::with_capacity(input.len() / 2);
input.iter().tuples().for_each(|(k, v)| {
@@ -119,7 +119,7 @@ where
);
});
- res
+ Ok(res)
}
}
class='deletions'>-3/+3 2021-05-26fix log breaking once buffer fullMax Audron-2/+33 the log_msg function was poping the newest message and replacing it with the newest message, it should be poping the oldest messages. 2021-05-16add deployment stuffMax Audron-6/+27786 2021-05-15add container buildMax Audron-2/+35