Skip to main content

selium_abi/
io.rs

1use rkyv::{Archive, Deserialize, Serialize};
2
3/// Backpressure behaviour for channel writers.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Archive, Serialize, Deserialize)]
5#[rkyv(bytecheck())]
6#[repr(u8)]
7pub enum ChannelBackpressure {
8    /// Writers wait for buffer space when the channel is full.
9    Park = 0,
10    /// Writers drop payloads when the channel is full.
11    Drop = 1,
12}
13
14/// Request to create a new channel.
15#[derive(Debug, Clone, PartialEq, Eq, Archive, Serialize, Deserialize)]
16#[rkyv(bytecheck())]
17pub struct ChannelCreate {
18    /// Channel capacity in bytes.
19    pub capacity: crate::GuestUint,
20    /// Backpressure behaviour for writers.
21    pub backpressure: ChannelBackpressure,
22}
23
24/// Request to read data from a reader.
25#[derive(Debug, Clone, PartialEq, Eq, Archive, Serialize, Deserialize)]
26#[rkyv(bytecheck())]
27pub struct IoRead {
28    /// Handle of the reader.
29    pub handle: crate::GuestUint,
30    /// Maximum number of bytes to read.
31    pub len: crate::GuestUint,
32}
33
34/// Request to write data to a writer.
35#[derive(Debug, Clone, PartialEq, Eq, Archive, Serialize, Deserialize)]
36#[rkyv(bytecheck())]
37pub struct IoWrite {
38    /// Handle of the writer.
39    pub handle: crate::GuestUint,
40    /// Payload to be written.
41    pub payload: Vec<u8>,
42}
43
44/// Response carrying an attributed frame.
45#[derive(Debug, Clone, PartialEq, Eq, Archive, Serialize, Deserialize)]
46#[rkyv(bytecheck())]
47pub struct IoFrame {
48    /// Identifier of the writer that produced this frame.
49    pub writer_id: u16,
50    /// Frame payload.
51    pub payload: Vec<u8>,
52}