Coverage Report

Created: 2026-03-20 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/h2/src/frame/window_update.rs
Line
Count
Source
1
use crate::frame::{self, Error, Head, Kind, StreamId};
2
3
use bytes::BufMut;
4
5
const SIZE_INCREMENT_MASK: u32 = 1 << 31;
6
7
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
8
pub struct WindowUpdate {
9
    stream_id: StreamId,
10
    size_increment: u32,
11
}
12
13
impl WindowUpdate {
14
1.76k
    pub fn new(stream_id: StreamId, size_increment: u32) -> WindowUpdate {
15
1.76k
        WindowUpdate {
16
1.76k
            stream_id,
17
1.76k
            size_increment,
18
1.76k
        }
19
1.76k
    }
20
21
1.82k
    pub fn stream_id(&self) -> StreamId {
22
1.82k
        self.stream_id
23
1.82k
    }
24
25
1.28k
    pub fn size_increment(&self) -> u32 {
26
1.28k
        self.size_increment
27
1.28k
    }
28
29
    /// Builds a `WindowUpdate` frame from a raw frame.
30
1.83k
    pub fn load(head: Head, payload: &[u8]) -> Result<WindowUpdate, Error> {
31
1.83k
        debug_assert_eq!(head.kind(), crate::frame::Kind::WindowUpdate);
32
1.83k
        if payload.len() != 4 {
33
11
            return Err(Error::BadFrameSize);
34
1.82k
        }
35
36
        // Clear the most significant bit, as that is reserved and MUST be ignored
37
        // when received.
38
1.82k
        let size_increment = unpack_octets_4!(payload, 0, u32) & !SIZE_INCREMENT_MASK;
39
40
1.82k
        if size_increment == 0 {
41
1
            return Err(Error::InvalidWindowUpdateValue);
42
1.82k
        }
43
44
1.82k
        Ok(WindowUpdate {
45
1.82k
            stream_id: head.stream_id(),
46
1.82k
            size_increment,
47
1.82k
        })
48
1.83k
    }
49
50
34
    pub fn encode<B: BufMut>(&self, dst: &mut B) {
51
34
        tracing::trace!("encoding WINDOW_UPDATE; id={:?}", self.stream_id);
52
34
        let head = Head::new(Kind::WindowUpdate, 0, self.stream_id);
53
34
        head.encode(4, dst);
54
34
        dst.put_u32(self.size_increment);
55
34
    }
Unexecuted instantiation: <h2::frame::window_update::WindowUpdate>::encode::<bytes::bytes_mut::BytesMut>
<h2::frame::window_update::WindowUpdate>::encode::<bytes::bytes_mut::BytesMut>
Line
Count
Source
50
34
    pub fn encode<B: BufMut>(&self, dst: &mut B) {
51
34
        tracing::trace!("encoding WINDOW_UPDATE; id={:?}", self.stream_id);
52
34
        let head = Head::new(Kind::WindowUpdate, 0, self.stream_id);
53
34
        head.encode(4, dst);
54
34
        dst.put_u32(self.size_increment);
55
34
    }
56
}
57
58
impl<B> From<WindowUpdate> for frame::Frame<B> {
59
1.85k
    fn from(src: WindowUpdate) -> Self {
60
1.85k
        frame::Frame::WindowUpdate(src)
61
1.85k
    }
<h2::frame::Frame as core::convert::From<h2::frame::window_update::WindowUpdate>>::from
Line
Count
Source
59
1.82k
    fn from(src: WindowUpdate) -> Self {
60
1.82k
        frame::Frame::WindowUpdate(src)
61
1.82k
    }
<h2::frame::Frame<h2::proto::streams::prioritize::Prioritized<bytes::bytes::Bytes>> as core::convert::From<h2::frame::window_update::WindowUpdate>>::from
Line
Count
Source
59
34
    fn from(src: WindowUpdate) -> Self {
60
34
        frame::Frame::WindowUpdate(src)
61
34
    }
62
}