aboutsummaryrefslogtreecommitdiff
path: root/src/primitive/msgid.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/primitive/msgid.rs')
-rw-r--r--src/primitive/msgid.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/primitive/msgid.rs b/src/primitive/msgid.rs
index 27608fe..7f3e32f 100644
--- a/src/primitive/msgid.rs
+++ b/src/primitive/msgid.rs
@@ -8,9 +8,16 @@ pub struct MsgId(
use crate::error::ProtocolError;
use crate::{deserialize::*, serialize::*};
+use crate::serialize::UserType;
+
impl Serialize for MsgId {
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)
}
}
@@ -49,6 +56,10 @@ impl std::ops::Deref for MsgId {
}
}
+impl UserType for MsgId {
+ const NAME: &str = "MsgId";
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -69,9 +80,9 @@ mod tests {
pub fn msgid_serialize_test() {
let res = MsgId(1).serialize().unwrap();
let expected_bytes: &[u8] = if cfg!(feature = "long-message-id") {
- &[0, 0, 0, 0, 0, 0, 0, 1]
+ &[0, 0, 0, 5, 77, 115, 103, 73, 100, 0, 0, 0, 0, 0, 0, 0, 1]
} else {
- &[0, 0, 0, 1]
+ &[0, 0, 0, 5, 77, 115, 103, 73, 100, 0, 0, 0, 1]
};
assert_eq!(res, expected_bytes);
}