@@ 13,6 13,14 @@ pub struct Message {
pub enum MessageContent {
Text(String),
}
+impl MessageContent {
+ pub fn to_bytes(&self) -> Vec<u8> {
+ match self {
+ MessageContent::Text(text) => [&[0], text.as_bytes()].concat()
+ }
+ }
+}
+
impl Message {
pub fn to_bytes(&self) -> Vec<u8> {
let mut result = vec![self.other_recipients.len() as u8];
@@ 25,12 33,7 @@ impl Message {
result.extend(timestamp.to_be_bytes());
result.extend(hash.0);
}
- match &self.content {
- MessageContent::Text(text) => {
- result.push(0);
- result.extend(text.as_bytes());
- }
- };
+ result.extend(self.content.to_bytes());
result
}
pub fn from_bytes(raw: &[u8]) -> Option<Self> {