Class: Biryani::Frame::Settings
- Inherits:
-
Object
- Object
- Biryani::Frame::Settings
- Defined in:
- lib/biryani/frame/settings.rb
Instance Attribute Summary collapse
-
#f_type ⇒ Object
readonly
Returns the value of attribute f_type.
-
#setting ⇒ Object
readonly
Returns the value of attribute setting.
-
#stream_id ⇒ Object
readonly
Returns the value of attribute stream_id.
Class Method Summary collapse
-
.read(s, flags, stream_id) ⇒ Settings
rubocop: disable Metrics/AbcSize rubocop: disable Metrics/CyclomaticComplexity rubocop: disable Metrics/PerceivedComplexity.
Instance Method Summary collapse
- #ack? ⇒ Boolean
-
#initialize(ack, stream_id, setting) ⇒ Settings
constructor
A new instance of Settings.
- #length ⇒ Integer
- #to_binary_s ⇒ String
Constructor Details
Instance Attribute Details
#f_type ⇒ Object (readonly)
Returns the value of attribute f_type.
4 5 6 |
# File 'lib/biryani/frame/settings.rb', line 4 def f_type @f_type end |
#setting ⇒ Object (readonly)
Returns the value of attribute setting.
4 5 6 |
# File 'lib/biryani/frame/settings.rb', line 4 def setting @setting end |
#stream_id ⇒ Object (readonly)
Returns the value of attribute stream_id.
4 5 6 |
# File 'lib/biryani/frame/settings.rb', line 4 def stream_id @stream_id end |
Class Method Details
.read(s, flags, stream_id) ⇒ Settings
rubocop: disable Metrics/AbcSize rubocop: disable Metrics/CyclomaticComplexity rubocop: disable Metrics/PerceivedComplexity
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/biryani/frame/settings.rb', line 43 def self.read(s, flags, stream_id) return ConnectionError.new(ErrorCode::FRAME_SIZE_ERROR, 'SETTINGS payload length MUST be a multiple of 6') if s.bytesize % 6 != 0 ack = Frame.read_ack(flags) setting = s.unpack('nN' * (s.bytesize / 6)).each_slice(2).to_h return ConnectionError.new(ErrorCode::FRAME_SIZE_ERROR, 'SETTINGS MUST NOT have setting with ack') \ if ack && setting.any? return ConnectionError.new(ErrorCode::PROTOCOL_ERROR, 'invalid SETTINGS_ENABLE_PUSH') \ if setting.key?(SettingsID::SETTINGS_ENABLE_PUSH) && ![0, 1].include?(setting[SettingsID::SETTINGS_ENABLE_PUSH]) return ConnectionError.new(ErrorCode::PROTOCOL_ERROR, 'invalid SETTINGS_MAX_FRAME_SIZE') \ if setting.key?(SettingsID::SETTINGS_MAX_FRAME_SIZE) && setting[SettingsID::SETTINGS_MAX_FRAME_SIZE] < 16_384 return ConnectionError.new(ErrorCode::PROTOCOL_ERROR, 'invalid SETTINGS_MAX_FRAME_SIZE') \ if setting.key?(SettingsID::SETTINGS_MAX_FRAME_SIZE) && setting[SettingsID::SETTINGS_MAX_FRAME_SIZE] > 16_777_215 return ConnectionError.new(ErrorCode::FLOW_CONTROL_ERROR, 'invalid SETTINGS_INITIAL_WINDOW_SIZE') \ if setting.key?(SettingsID::SETTINGS_INITIAL_WINDOW_SIZE) && setting[SettingsID::SETTINGS_INITIAL_WINDOW_SIZE] > 2_147_483_647 Settings.new(ack, stream_id, setting) end |
Instance Method Details
#ack? ⇒ Boolean
17 18 19 |
# File 'lib/biryani/frame/settings.rb', line 17 def ack? @ack end |
#length ⇒ Integer
22 23 24 |
# File 'lib/biryani/frame/settings.rb', line 22 def length @setting.length * 6 end |
#to_binary_s ⇒ String
27 28 29 30 31 32 33 |
# File 'lib/biryani/frame/settings.rb', line 27 def to_binary_s payload_length = length flags = Frame.to_flags(ack: ack?) setting = @setting.map { |x| x.pack('nN') }.join Frame.to_binary_s_header(payload_length, @f_type, flags, @stream_id) + setting end |