From 6f9c0d0f2906d05e27f9f11af6cefdf006c2cf4b Mon Sep 17 00:00:00 2001 From: Max Audron Date: Wed, 26 Feb 2025 17:53:08 +0100 Subject: refactor variant serialization code Factored out a lot of the serialization of variants into trait's that have auto impl so code duplication is much reduced --- src/deserialize.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/deserialize.rs (limited to 'src/deserialize.rs') diff --git a/src/deserialize.rs b/src/deserialize.rs new file mode 100644 index 0000000..e13f21f --- /dev/null +++ b/src/deserialize.rs @@ -0,0 +1,21 @@ +use crate::error::ProtocolError; + +/// Deserialization of types and structs to the quassel byteprotocol +pub trait Deserialize { + 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), ProtocolError> + where + Self: std::marker::Sized; +} + +pub trait DeserializeVariant { + fn parse_variant(b: &[u8]) -> Result<(usize, Self), ProtocolError> + where + Self: std::marker::Sized; +} -- cgit v1.2.3