1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use anyhow::Result;
use zerocopy::Unaligned;

use super::TransferFrame;

#[async_trait::async_trait]
pub trait SyncAndChannelCoding {
    async fn receive(&mut self) -> Result<TransferFrameBuffer>;
}

pub struct TransferFrameBuffer {
    bytes: Vec<u8>,
}

impl TransferFrameBuffer {
    pub fn new(bytes: Vec<u8>) -> Self {
        Self { bytes }
    }

    pub fn transfer_frame<T: Unaligned>(&self) -> Option<TransferFrame<&[u8], T>> {
        TransferFrame::<_, T>::new(self.bytes.as_slice())
    }

    pub fn into_inner(self) -> Vec<u8> {
        self.bytes
    }
}