1use crate::pb::Frame;
4use bytes::{Bytes, BytesMut};
5use prost::Message;
6
7#[derive(Debug, thiserror::Error)]
8pub enum FrameError {
9 #[error("failed to decode Frame: {0}")]
10 Decode(#[from] prost::DecodeError),
11}
12
13pub fn decode_frame(bytes: &[u8]) -> Result<Frame, FrameError> {
15 Ok(Frame::decode(bytes)?)
16}
17
18pub fn encode_frame(frame: &Frame) -> Bytes {
20 let mut buf = BytesMut::with_capacity(frame.encoded_len());
21 frame.encode(&mut buf).expect("BytesMut has capacity");
22 buf.freeze()
23}