1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#![warn(missing_docs)]
//! utils of service
use crate::error::Error;
use crate::error::Result;
use crate::prelude::*;

/// send chunk report message
pub async fn send_chunk_report_message(
    ctx: &MessagePayload<Message>,
    data: &[u8],
) -> Result<MessageHandlerEvent> {
    let mut new_bytes: Vec<u8> = Vec::with_capacity(data.len() + 1);
    new_bytes.push(1);
    new_bytes.extend_from_slice(&[0u8; 3]);
    new_bytes.extend_from_slice(data);

    Ok(MessageHandlerEvent::SendReportMessage(
        ctx.clone(),
        Message::custom(&new_bytes).map_err(|_| Error::InvalidMessage)?,
    ))
}