sheave_core/messages/headers/
basic.rs

1mod message_format;
2
3pub use self::message_format::MessageFormat;
4
5/// Indicates the chunk stream and message header's format.
6///
7/// This header has 3 types.
8///
9/// |Total|Message Header Format|Chunk ID|Chunk ID Range|
10/// | -: | -: | -: | -: |
11/// | 8|2| 6| 0 -    63|
12/// |16|2| 8|64 -   319|
13/// |24|2|16|64 - 65599|
14///
15/// The unit of every length item is bits.
16/// Basic header which is and above 16 bits has a flag bits in first 8 bits.
17/// It means whether chunk ID is 16 bits.
18/// Note if chunk ID is 16 bits, encoding/decoding it as Little Endian is required.
19///
20/// Any chunk ID which is and above 64 is required to add/subtract 64 from it when reading/writing.
21/// This means to compensate a 6 bits which was replaced with the flag.
22#[derive(Debug, Clone, Copy)]
23pub struct BasicHeader {
24    message_format: MessageFormat,
25    chunk_id: u16
26}
27
28impl BasicHeader {
29    /// Constructs a new basic header.
30    pub fn new(message_format: MessageFormat, chunk_id: u16) -> Self {
31        Self { message_format, chunk_id }
32    }
33
34    /// Gets the message format.
35    pub fn get_message_format(&self) -> MessageFormat {
36        self.message_format
37    }
38
39    /// Gets the chunk ID.
40    pub fn get_chunk_id(&self) -> u16 {
41        self.chunk_id
42    }
43}