Class: HTTP2::FrameBuffer
- Inherits:
-
Object
- Object
- HTTP2::FrameBuffer
- Includes:
- BufferUtils
- Defined in:
- lib/http/2/flow_buffer.rb,
sig/frame_buffer.rbs
Instance Attribute Summary collapse
-
#bytesize ⇒ Integer
readonly
Returns the value of attribute bytesize.
Instance Method Summary collapse
- #<<(frame) ⇒ void
- #clear ⇒ void
- #empty? ⇒ Boolean
-
#initialize ⇒ FrameBuffer
constructor
A new instance of FrameBuffer.
- #retrieve(window_size) ⇒ data_frame_props?
Methods included from BufferUtils
#append_str, #read_str, #read_uint32, #shift_byte
Constructor Details
#initialize ⇒ FrameBuffer
Returns a new instance of FrameBuffer.
122 123 124 125 |
# File 'lib/http/2/flow_buffer.rb', line 122 def initialize @buffer = [] @bytesize = 0 end |
Instance Attribute Details
#bytesize ⇒ Integer (readonly)
Returns the value of attribute bytesize.
120 121 122 |
# File 'lib/http/2/flow_buffer.rb', line 120 def bytesize @bytesize end |
Instance Method Details
#<<(frame) ⇒ void
This method returns an undefined value.
127 128 129 130 |
# File 'lib/http/2/flow_buffer.rb', line 127 def <<(frame) @buffer << frame @bytesize += frame[:payload].bytesize end |
#clear ⇒ void
This method returns an undefined value.
132 133 134 135 |
# File 'lib/http/2/flow_buffer.rb', line 132 def clear @buffer.clear @bytesize = 0 end |
#empty? ⇒ Boolean
137 138 139 |
# File 'lib/http/2/flow_buffer.rb', line 137 def empty? @buffer.empty? end |
#retrieve(window_size) ⇒ data_frame_props?
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/http/2/flow_buffer.rb', line 141 def retrieve(window_size) frame = @buffer.first or return frame_size = frame[:payload].bytesize end_stream = frame[:flags].anybits?(END_STREAM) # Frames with zero length with the END_STREAM flag set (that # is, an empty DATA frame) MAY be sent if there is no available space # in either flow control window. return if window_size <= 0 && !(frame_size.zero? && end_stream) if frame_size > window_size chunk = frame.dup # Split frame so that it fits in the window # TODO: consider padding! chunk[:payload] = read_str(frame[:payload], window_size) # mutates frame[:payload] chunk[:length] = window_size frame[:length] = frame_size - window_size # if no longer last frame in sequence... chunk[:flags] ^= END_STREAM if end_stream @bytesize -= window_size chunk else @bytesize -= frame_size @buffer.shift end end |