pub struct Channel<D, T, Tr, C: CodecFor<T>> { /* private fields */ }Expand description
A typed, directed communication endpoint over a transport half.
§Type parameters
D- direction:TxorRxT- message typeTr- send half (SendTransport) forTx, receive half (RecvTransport) forRxC- codec; anyCodecFor<T>family, e.g.consortium_codec::PostcardCodec
§Buffer ownership
Channel does not allocate. The caller provides a &'static mut [u8]
scratch buffer at construction. In no_std environments this is
typically a static array — see consortium_runtime_mcu::static_buf! for a
helper that takes the raw static mut out of application code:
use consortium_codec::PostcardCodec;
use consortium_ipc::{Channel, Tx};
static mut BUF: [u8; 256] = [0u8; 256];
// Taking the one and only reference to BUF.
let buf = unsafe { &mut *core::ptr::addr_of_mut!(BUF) };
let ch = Channel::<Tx, MyMsg, _, PostcardCodec>::new(chan, transport, buf);The buffer must be at least transport.max_send_size() / max_recv_size() bytes.
Implementations§
Source§impl<T, Tr, C> Channel<Rx, T, Tr, C>where
Tr: RecvTransport,
C: CodecFor<T>,
impl<T, Tr, C> Channel<Rx, T, Tr, C>where
Tr: RecvTransport,
C: CodecFor<T>,
Sourcepub async fn recv(
&mut self,
) -> Result<ReceivedMessage<'_, T, C>, ChannelError<C, Tr>>
pub async fn recv( &mut self, ) -> Result<ReceivedMessage<'_, T, C>, ChannelError<C, Tr>>
Await the next message from the transport and decode it.
Blocks until the transport’s doorbell fires and bytes arrive.
Returns a ReceivedMessage wrapping the decoded value.
When C = PostcardCodec the message is an owned T.
When C is a future zero-copy codec the returned handle will
borrow the internal buffer - the '_ lifetime on
ReceivedMessage already accommodates this without any
change to this signature.