File: window_update_frame.rb

package info (click to toggle)
ruby-protocol-http2 0.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 472 kB
  • sloc: ruby: 3,627; makefile: 4
file content (51 lines) | stat: -rw-r--r-- 1,492 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2019-2025, by Samuel Williams.

require_relative "frame"
require_relative "window"

module Protocol
	module HTTP2
		# The WINDOW_UPDATE frame is used to implement flow control.
		#
		# +-+-------------------------------------------------------------+
		# |R|              Window Size Increment (31)                     |
		# +-+-------------------------------------------------------------+
		#
		class WindowUpdateFrame < Frame
			TYPE = 0x8
			FORMAT = "N"
			
			# Pack a window size increment into the frame.
			# @parameter window_size_increment [Integer] The window size increment value.
			def pack(window_size_increment)
				super [window_size_increment].pack(FORMAT)
			end
			
			# Unpack the window size increment from the frame payload.
			# @returns [Integer] The window size increment value.
			def unpack
				super.unpack1(FORMAT)
			end
			
			# Read and validate the WINDOW_UPDATE frame payload.
			# @parameter stream [IO] The stream to read from.
			# @raises [FrameSizeError] If the frame length is invalid.
			def read_payload(stream)
				super
				
				if @length != 4
					raise FrameSizeError, "Invalid frame length: #{@length} != 4!"
				end
			end
			
			# Apply this WINDOW_UPDATE frame to a connection for processing.
			# @parameter connection [Connection] The connection to apply the frame to.
			def apply(connection)
				connection.receive_window_update(self)
			end
		end
	end
end