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