aboutsummaryrefslogtreecommitdiff
path: root/src/primitive/bufferid.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/bufferid.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 'src/primitive/bufferid.rs')
-rw-r--r--src/primitive/bufferid.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/primitive/bufferid.rs b/src/primitive/bufferid.rs
index 4be867d..1735473 100644
--- a/src/primitive/bufferid.rs
+++ b/src/primitive/bufferid.rs
@@ -4,9 +4,16 @@ pub struct BufferId(pub i32);
use crate::{deserialize::*, error::ProtocolError, serialize::*};
+use crate::serialize::UserType;
+
impl Serialize for BufferId {
fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
- self.0.serialize()
+ let mut res = Vec::new();
+
+ res.append(&mut Self::NAME.serialize_utf8()?);
+ res.extend(self.0.serialize()?);
+
+ Ok(res)
}
}
@@ -31,6 +38,10 @@ impl std::ops::Deref for BufferId {
}
}
+impl UserType for BufferId {
+ const NAME: &str = "BufferId";
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -46,7 +57,7 @@ mod tests {
#[test]
pub fn bufferid_serialize_test() {
let res = BufferId(1).serialize().unwrap();
- let expected_bytes: &[u8] = &[0, 0, 0, 1];
+ let expected_bytes: &[u8] = &[0, 0, 0, 8, 66, 117, 102, 102, 101, 114, 73, 100, 0, 0, 0, 1];
assert_eq!(res, expected_bytes);
}
}