~yujiri/libsufec

945147f98dbfa5d4ae15958ece50a8ec1b59be95 — Yujiri 2 years ago 52e22b4
add MessageContent::to_bytes to simplify hashing in clients
1 files changed, 9 insertions(+), 6 deletions(-)

M src/message.rs
M src/message.rs => src/message.rs +9 -6
@@ 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> {