Skip to main content

net_wire/http2/
priority.rs

1/// The priority section carried by a HEADERS frame.
2#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3pub struct Http2Priority {
4    raw_dependency: u32,
5    weight: u8,
6}
7
8impl Http2Priority {
9    /// Creates a priority section from its raw dependency field and encoded weight.
10    pub const fn new(raw_dependency: u32, weight: u8) -> Self {
11        Self {
12            raw_dependency,
13            weight,
14        }
15    }
16
17    pub(super) fn parse(bytes: &[u8]) -> Self {
18        Self {
19            raw_dependency: u32::from_be_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]),
20            weight: bytes[4],
21        }
22    }
23
24    /// Returns whether the exclusive dependency bit is set.
25    pub const fn is_exclusive(self) -> bool {
26        self.raw_dependency & 0x8000_0000 != 0
27    }
28
29    /// Returns the raw dependency field, including the exclusive bit.
30    pub const fn raw_dependency(self) -> u32 {
31        self.raw_dependency
32    }
33
34    /// Returns the 31-bit stream dependency value.
35    pub const fn dependency(self) -> u32 {
36        self.raw_dependency & 0x7fff_ffff
37    }
38
39    /// Returns the raw encoded weight.
40    pub const fn weight(self) -> u8 {
41        self.weight
42    }
43}