aboutsummaryrefslogtreecommitdiff
path: root/src/primitive/unsignedint.rs
diff options
context:
space:
mode:
authorMax Audron <audron@cocaine.farm>2025-02-26 17:53:08 +0100
committerMax Audron <audron@cocaine.farm>2025-02-26 17:53:08 +0100
commit6f9c0d0f2906d05e27f9f11af6cefdf006c2cf4b (patch)
tree3c92d681f8c98786bf7371ecfece60ed4f8d4a7c /src/primitive/unsignedint.rs
parentadd MsgId and BufferId to objects where needed (diff)
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
Diffstat (limited to '')
-rw-r--r--src/primitive/unsignedint.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/primitive/unsignedint.rs b/src/primitive/unsignedint.rs
index b5d76cd..f0a78f7 100644
--- a/src/primitive/unsignedint.rs
+++ b/src/primitive/unsignedint.rs
@@ -6,7 +6,9 @@ use std::result::Result;
use std::vec::Vec;
use crate::error::ProtocolError;
-use crate::{deserialize::*, serialize::*};
+use crate::{deserialize::*, primitive, serialize::*};
+
+use crate::serialize::SerializeVariant;
impl Serialize for bool {
fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
@@ -29,6 +31,10 @@ impl Deserialize for bool {
}
}
+impl SerializeVariant for bool {
+ const TYPE: u32 = primitive::BOOL;
+}
+
impl Serialize for u64 {
fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
Ok(Vec::from(self.to_be_bytes()))
@@ -42,6 +48,10 @@ impl Deserialize for u64 {
}
}
+impl SerializeVariant for u64 {
+ const TYPE: u32 = primitive::ULONG;
+}
+
impl Serialize for u32 {
fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
Ok(Vec::from(self.to_be_bytes()))
@@ -55,6 +65,10 @@ impl Deserialize for u32 {
}
}
+impl SerializeVariant for u32 {
+ const TYPE: u32 = primitive::UINT;
+}
+
impl Serialize for u16 {
fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
Ok(Vec::from(self.to_be_bytes()))
@@ -68,6 +82,10 @@ impl Deserialize for u16 {
}
}
+impl SerializeVariant for u16 {
+ const TYPE: u32 = primitive::USHORT;
+}
+
impl Serialize for u8 {
fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
Ok(Vec::from(self.to_be_bytes()))
@@ -79,3 +97,7 @@ impl Deserialize for u8 {
return Ok((1, b[0]));
}
}
+
+impl SerializeVariant for u8 {
+ const TYPE: u32 = primitive::UCHAR;
+}