Class: Biryani::Frame::Data
- Inherits:
-
Object
- Object
- Biryani::Frame::Data
- Defined in:
- lib/biryani/frame/data.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#f_type ⇒ Object
readonly
Returns the value of attribute f_type.
-
#padding ⇒ Object
readonly
Returns the value of attribute padding.
-
#stream_id ⇒ Object
readonly
Returns the value of attribute stream_id.
Class Method Summary collapse
Instance Method Summary collapse
- #end_stream? ⇒ Boolean
-
#initialize(end_stream, stream_id, data, padding) ⇒ Data
constructor
A new instance of Data.
- #length ⇒ Integer
- #padded? ⇒ Boolean
- #to_binary_s ⇒ String
Constructor Details
#initialize(end_stream, stream_id, data, padding) ⇒ Data
Returns a new instance of Data.
10 11 12 13 14 15 16 |
# File 'lib/biryani/frame/data.rb', line 10 def initialize(end_stream, stream_id, data, padding) @f_type = FrameType::DATA @end_stream = end_stream @stream_id = stream_id @data = data @padding = padding end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/biryani/frame/data.rb', line 4 def data @data end |
#f_type ⇒ Object (readonly)
Returns the value of attribute f_type.
4 5 6 |
# File 'lib/biryani/frame/data.rb', line 4 def f_type @f_type end |
#padding ⇒ Object (readonly)
Returns the value of attribute padding.
4 5 6 |
# File 'lib/biryani/frame/data.rb', line 4 def padding @padding end |
#stream_id ⇒ Object (readonly)
Returns the value of attribute stream_id.
4 5 6 |
# File 'lib/biryani/frame/data.rb', line 4 def stream_id @stream_id end |
Class Method Details
.read(s, flags, stream_id) ⇒ Data
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/biryani/frame/data.rb', line 48 def self.read(s, flags, stream_id) padded = Frame.read_padded(flags) end_stream = Frame.read_end_stream(flags) if padded io = IO::Buffer.for(s) pad_length = io.get_value(:U8, 0) data_length = s.bytesize - pad_length - 1 data = io.get_string(1, data_length) padding = io.get_string(1 + data_length) return ConnectionError.new(ErrorCode::PROTOCOL_ERROR, 'invalid frame') if padding.bytesize != pad_length else data = s end Data.new(end_stream, stream_id, data, padding) end |
Instance Method Details
#end_stream? ⇒ Boolean
24 25 26 |
# File 'lib/biryani/frame/data.rb', line 24 def end_stream? @end_stream end |
#length ⇒ Integer
29 30 31 |
# File 'lib/biryani/frame/data.rb', line 29 def length @data.bytesize + (padded? ? 1 + @padding.bytesize : 0) end |
#padded? ⇒ Boolean
19 20 21 |
# File 'lib/biryani/frame/data.rb', line 19 def padded? !@padding.nil? end |
#to_binary_s ⇒ String
34 35 36 37 38 39 40 41 |
# File 'lib/biryani/frame/data.rb', line 34 def to_binary_s payload_length = length flags = Frame.to_flags(padded: padded?, end_stream: end_stream?) pad_length = padded? ? @padding.bytesize.chr : '' padding = @padding || '' Frame.to_binary_s_header(payload_length, @f_type, flags, @stream_id) + pad_length + @data + padding end |