ergot_base/interface_manager/utils/
std.rs

1use std::sync::Arc;
2
3use bbq2::{
4    queue::BBQueue,
5    traits::{coordination::cas::AtomicCoord, notifier::maitake::MaiNotSpsc, storage::BoxedSlice},
6};
7
8#[derive(Debug, PartialEq)]
9pub enum ReceiverError {
10    SocketClosed,
11}
12
13/// A type alias for the kind of queue used on std devices.
14pub type StdQueue = Arc<BBQueue<BoxedSlice, AtomicCoord, MaiNotSpsc>>;
15
16/// Create a new StdQueue with the given buffer size
17pub fn new_std_queue(buffer: usize) -> StdQueue {
18    Arc::new(BBQueue::new_with_storage(BoxedSlice::new(buffer)))
19}
20
21pub(crate) mod acc {
22    //! Basically postcard's cobs accumulator, but without the deser part
23
24    pub use cobs_acc::FeedResult;
25
26    pub struct CobsAccumulator {
27        inner: cobs_acc::CobsAccumulator<Box<[u8]>>,
28    }
29
30    impl CobsAccumulator {
31        #[inline]
32        pub fn new(size: usize) -> Self {
33            Self {
34                inner: cobs_acc::CobsAccumulator::new_boxslice(size),
35            }
36        }
37
38        #[inline(always)]
39        pub fn feed_raw<'me, 'input>(
40            &'me mut self,
41            input: &'input mut [u8],
42        ) -> FeedResult<'input, 'me> {
43            self.inner.feed_raw(input)
44        }
45    }
46}