Class: Biryani::Frame::PushPromise
- Inherits:
-
Object
- Object
- Biryani::Frame::PushPromise
- Defined in:
- lib/biryani/frame/push_promise.rb
Instance Attribute Summary collapse
-
#f_type ⇒ Object
readonly
Returns the value of attribute f_type.
-
#fragment ⇒ Object
readonly
Returns the value of attribute fragment.
-
#padding ⇒ Object
readonly
Returns the value of attribute padding.
-
#promised_stream_id ⇒ Object
readonly
Returns the value of attribute promised_stream_id.
-
#stream_id ⇒ Object
readonly
Returns the value of attribute stream_id.
Class Method Summary collapse
Instance Method Summary collapse
- #end_headers? ⇒ Boolean
-
#initialize(end_headers, stream_id, promised_stream_id, fragment, padding) ⇒ PushPromise
constructor
A new instance of PushPromise.
- #length ⇒ Integer
- #padded? ⇒ Boolean
- #to_binary_s ⇒ String
Constructor Details
#initialize(end_headers, stream_id, promised_stream_id, fragment, padding) ⇒ PushPromise
Returns a new instance of PushPromise.
11 12 13 14 15 16 17 18 |
# File 'lib/biryani/frame/push_promise.rb', line 11 def initialize(end_headers, stream_id, promised_stream_id, fragment, padding) @f_type = FrameType::PUSH_PROMISE @end_headers = end_headers @stream_id = stream_id @promised_stream_id = promised_stream_id @fragment = fragment @padding = padding end |
Instance Attribute Details
#f_type ⇒ Object (readonly)
Returns the value of attribute f_type.
4 5 6 |
# File 'lib/biryani/frame/push_promise.rb', line 4 def f_type @f_type end |
#fragment ⇒ Object (readonly)
Returns the value of attribute fragment.
4 5 6 |
# File 'lib/biryani/frame/push_promise.rb', line 4 def fragment @fragment end |
#padding ⇒ Object (readonly)
Returns the value of attribute padding.
4 5 6 |
# File 'lib/biryani/frame/push_promise.rb', line 4 def padding @padding end |
#promised_stream_id ⇒ Object (readonly)
Returns the value of attribute promised_stream_id.
4 5 6 |
# File 'lib/biryani/frame/push_promise.rb', line 4 def promised_stream_id @promised_stream_id end |
#stream_id ⇒ Object (readonly)
Returns the value of attribute stream_id.
4 5 6 |
# File 'lib/biryani/frame/push_promise.rb', line 4 def stream_id @stream_id end |
Class Method Details
.read(s, flags, stream_id) ⇒ PushPromise
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/biryani/frame/push_promise.rb', line 50 def self.read(s, flags, stream_id) padded = Frame.read_padded(flags) end_headers = Frame.read_end_headers(flags) io = IO::Buffer.for(s) if padded pad_length, promised_stream_id = io.get_values(%i[U8 U32], 0) promised_stream_id %= 2**31 # Promised Stream ID (31) fragment_length = s.bytesize - pad_length - 5 fragment = io.get_string(5, fragment_length) padding = io.get_string(5 + fragment_length) return ConnectionError.new(ErrorCode::PROTOCOL_ERROR, 'invalid frame') if pad_length >= s.bytesize return ConnectionError.new(ErrorCode::PROTOCOL_ERROR, 'invalid frame') if padding.bytesize != pad_length else promised_stream_id = io.get_value(:U32, 0) promised_stream_id %= 2**31 # Promised Stream ID (31) fragment = io.get_string(4) return ConnectionError.new(ErrorCode::PROTOCOL_ERROR, 'invalid frame') if fragment.bytesize + 4 != s.bytesize end PushPromise.new(end_headers, stream_id, promised_stream_id, fragment, padding) end |
Instance Method Details
#end_headers? ⇒ Boolean
26 27 28 |
# File 'lib/biryani/frame/push_promise.rb', line 26 def end_headers? @end_headers end |
#length ⇒ Integer
31 32 33 |
# File 'lib/biryani/frame/push_promise.rb', line 31 def length @fragment.bytesize + 4 + (padded? ? 1 + @padding.bytesize : 0) end |
#padded? ⇒ Boolean
21 22 23 |
# File 'lib/biryani/frame/push_promise.rb', line 21 def padded? !@padding.nil? end |
#to_binary_s ⇒ String
36 37 38 39 40 41 42 43 |
# File 'lib/biryani/frame/push_promise.rb', line 36 def to_binary_s payload_length = length flags = Frame.to_flags(padded: padded?, end_headers: end_headers?) pad_length = padded? ? @padding.bytesize.chr : '' padding = @padding || '' Frame.to_binary_s_header(payload_length, @f_type, flags, @stream_id) + pad_length + [@promised_stream_id].pack('N') + @fragment + padding end |