aboutsummaryrefslogtreecommitdiff
path: root/src/serialize.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/serialize.rs66
1 files changed, 60 insertions, 6 deletions
diff --git a/src/serialize.rs b/src/serialize.rs
index 925b668..dffd0c3 100644
--- a/src/serialize.rs
+++ b/src/serialize.rs
@@ -1,3 +1,51 @@
+//! Traits for Serializing and Deserializing types to their byte representations
+//!
+//! example for a simple type would look like this with the `TYPE` usually fetched from [libquassel::primitive#constants]
+//!
+//! ```rust
+//! use libquassel::{ProtocolError, serialize::*};
+//!
+//! pub struct Example;
+//!
+//! impl Serialize for Example {
+//! fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
+//! // Serialize here
+//! # todo!()
+//! }
+//! }
+//!
+//! impl Deserialize for Example {
+//! fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
+//! // Deserialize here
+//! # todo!()
+//! }
+//! }
+//!
+//! impl VariantType for Example {
+//! // The QT Type identifier
+//! const TYPE: u32 = 0x18;
+//! }
+//! ```
+//!
+//! Some types are not serialized directly but are a [UserType]:
+//! ```rust
+//! use libquassel::{ProtocolError, serialize::*};
+//!
+//! pub struct Example;
+//!
+//! impl Serialize for Example {
+//! fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
+//! // Serialize here
+//! # todo!()
+//! }
+//! }
+//!
+//! impl UserType for Example {
+//! const NAME: &str = "Example";
+//! }
+//! ```
+//! [UserType]: libquassel::serialize::UserType
+
use crate::{
error::ProtocolError,
primitive::{self, Variant},
@@ -64,13 +112,11 @@ pub trait VariantType {
const TYPE: u32;
}
+/// Serialize a Type directly to it's Variant.
+///
+/// Has a default implementation and is automaticly implemented for all types that
+/// have a [VariantType] set and [Serialize] implemented.
pub trait SerializeVariant: VariantType + Serialize {
- /// Default implementation that passes the serialization through to [SerializeVariantInner].
- /// [SerializeVariantInner] is automaticly implemented for all types that implement [Serialize]
- ///
- /// ```rust ignore
- /// self.serialize_variant_inner(Self::TYPE)
- /// ```
fn serialize_variant(&self) -> Result<Vec<u8>, ProtocolError> {
let mut res: Vec<u8> = Vec::new();
@@ -102,6 +148,14 @@ pub trait DeserializeUTF8 {
Self: std::marker::Sized;
}
+/// Deserialize a Type for use in the Variant parsing. In opposite to [SerializeVariant] this does not deal
+/// with the variant type itself as we have to match onto it genericly before passing it on to per Type
+/// functions.
+///
+/// Still using this gives us automatic implementations and more code reuse
+///
+/// Has a default implementation and is automaticly implemented for all types that
+/// have a [VariantType] set and [Deserialize] implemented.
pub trait DeserializeVariant: VariantType + Deserialize
where
Variant: From<Self>,
2021-06-11Release version 1.2.01.2.0Max Audron-2/+2 * add pet command 2021-06-06make pet more compactR0flcopt3r/catinator-pet-commandMax Audron-5/+5 2021-06-05feat: adds pet command.R0flcopt3r-0/+90 When petting the cat it will reply with some random action. 2021-06-05feat: send actionR0flcopt3r-1/+9 2021-06-05release version 1.1.0Max Audron-2/+2 2021-06-05document proc macrosMax Audron-4/+97 2021-06-05add intensifyMax Audron-3/+27 2021-06-05add privmsg macroMax Audron-2/+40 2021-06-05fix jb remote urlsMax Audron-4/+4 2021-06-05remove egress gateway configMax Audron-10/+0 2021-06-05update tanka dependenciesMax Audron-8/+8 2021-06-05fix init container nameMax Audron-1/+1 2021-06-05fix tanka dependency pathMax Audron-8/+8 2021-06-05switch to https url for tanka util libMax Audron-2/+2 2021-06-05bump version to 1.0.2Max Audron-2/+2 2021-06-05add tanka ci configurationMax Audron-1/+1 2021-06-05ready tanka deploy for CIMax Audron-32/+69 2021-06-05remove tanka vendoringMax Audron-27651/+0 2021-05-26Release 1.0.1Max Audron-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