Class: Biryani::DataBuffer
- Inherits:
-
Object
- Object
- Biryani::DataBuffer
- Defined in:
- lib/biryani/data_buffer.rb
Instance Method Summary collapse
- #has?(stream_id) ⇒ Boolean
-
#initialize ⇒ DataBuffer
constructor
A new instance of DataBuffer.
- #length ⇒ Integer
- #store(stream_id, data) ⇒ Object
-
#take!(send_window, streams_ctx, max_frame_size) ⇒ Array<Object>
Frames.
Constructor Details
#initialize ⇒ DataBuffer
Returns a new instance of DataBuffer.
3 4 5 |
# File 'lib/biryani/data_buffer.rb', line 3 def initialize @buffer = {} # Hash<Integer, String> end |
Instance Method Details
#has?(stream_id) ⇒ Boolean
46 47 48 |
# File 'lib/biryani/data_buffer.rb', line 46 def has?(stream_id) @buffer.key?(stream_id) end |
#length ⇒ Integer
39 40 41 |
# File 'lib/biryani/data_buffer.rb', line 39 def length @buffer.length end |
#store(stream_id, data) ⇒ Object
9 10 11 12 |
# File 'lib/biryani/data_buffer.rb', line 9 def store(stream_id, data) @buffer[stream_id] = '' unless @buffer.key?(stream_id) @buffer[stream_id] << data end |
#take!(send_window, streams_ctx, max_frame_size) ⇒ Array<Object>
Returns frames.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/biryani/data_buffer.rb', line 19 def take!(send_window, streams_ctx, max_frame_size) datas = [] @buffer.each do |stream_id, data| frames, remains = streams_ctx.sendable_datas(stream_id, data, send_window, max_frame_size) datas += frames if remains.empty? @buffer.delete(stream_id) else @buffer[stream_id] = remains end len = frames.map(&:length).sum send_window.consume!(len) streams_ctx[stream_id].send_window.consume!(len) end datas end |