Skip to main content

muxio_core/frame/
frame_struct.rs

1use crate::frame::{FrameDecodeError, FrameKind};
2
3/// Represents a single frame of data in the stream.
4///
5/// A frame is the basic unit of data that is transmitted in the system. It consists
6/// of a header with metadata, such as the stream ID, sequence ID, timestamp, and
7/// a payload that contains the actual data being sent.
8///
9/// A single frame is not necessarily a single chunk of data — multiple frames or even
10/// portions of frames may be bundled together in an actual data chunk, depending on
11/// the transport protocol.
12#[derive(Debug)]
13pub struct Frame {
14    /// Identifies the logical stream or message.
15    ///
16    /// The `stream_id` is used to distinguish between different streams of data.
17    /// Each logical connection or communication channel has a unique `stream_id`.
18    pub stream_id: u32,
19
20    /// The sequence number of the frame within the stream.
21    ///
22    /// The `seq_id` helps maintain the order of frames within the same stream.
23    /// It ensures that the frames are processed in the correct sequence, even if
24    /// they arrive out of order.
25    pub seq_id: u32,
26
27    /// The type of frame.
28    ///
29    /// The `kind` field specifies the frame's role in the communication.
30    /// Possible values include `Open`, `Data`, `End`, `Cancel`, `Pong`, `Ping`,
31    /// which define whether the frame is part of an active stream, the data itself,
32    /// or control messages like stream termination or cancellation.
33    pub kind: FrameKind, // Open, Data, End, etc.
34
35    /// The timestamp when the frame was sent, in microseconds since the UNIX epoch.
36    ///
37    /// The `timestamp_micros` provides the time when the frame was generated or sent.
38    /// It is used for various purposes such as measuring latency or sequencing frames
39    /// that have been generated in different time windows.
40    pub timestamp_micros: u64, // Local send timestamp
41
42    /// The raw payload data of the frame.
43    ///
44    /// The `payload` is the actual data being transmitted in the frame. It is represented
45    /// as a vector of bytes, and its interpretation is left to the application layer.
46    /// This could contain any kind of application-specific data.
47    pub payload: Vec<u8>,
48}
49
50#[derive(Debug)]
51pub struct DecodedFrame {
52    pub inner: Frame,
53    pub decode_error: Option<FrameDecodeError>,
54}