Class: Biryani::Frame::Priority

Inherits:
Object
  • Object
show all
Defined in:
lib/biryani/frame/priority.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream_id, stream_dependency, weight) ⇒ Priority

Returns a new instance of Priority.

Parameters:

  • stream_id (Integer)
  • stream_dependency (Integer)
  • weight (Integer)


9
10
11
12
13
14
# File 'lib/biryani/frame/priority.rb', line 9

def initialize(stream_id, stream_dependency, weight)
  @f_type = FrameType::PRIORITY
  @stream_id = stream_id
  @stream_dependency = stream_dependency
  @weight = weight
end

Instance Attribute Details

#f_typeObject (readonly)

Returns the value of attribute f_type.



4
5
6
# File 'lib/biryani/frame/priority.rb', line 4

def f_type
  @f_type
end

#stream_dependencyObject (readonly)

Returns the value of attribute stream_dependency.



4
5
6
# File 'lib/biryani/frame/priority.rb', line 4

def stream_dependency
  @stream_dependency
end

#stream_idObject (readonly)

Returns the value of attribute stream_id.



4
5
6
# File 'lib/biryani/frame/priority.rb', line 4

def stream_id
  @stream_id
end

#weightObject (readonly)

Returns the value of attribute weight.



4
5
6
# File 'lib/biryani/frame/priority.rb', line 4

def weight
  @weight
end

Class Method Details

.read(s, _flags, stream_id) ⇒ Priority

Parameters:

  • s (String)
  • _flags (Integer)
  • stream_id (Integer)

Returns:



34
35
36
37
38
39
40
41
42
# File 'lib/biryani/frame/priority.rb', line 34

def self.read(s, _flags, stream_id)
  return ConnectionError.new(ErrorCode::FRAME_SIZE_ERROR, 'PRIORITY payload length MUST be 5') if s.bytesize != 5

  stream_dependency, weight = s.unpack('NC')
  stream_dependency %= 2**31
  return ConnectionError.new(ErrorCode::PROTOCOL_ERROR, 'cannot depend on itself') if stream_dependency == stream_id

  Priority.new(stream_id, stream_dependency, weight)
end

Instance Method Details

#lengthInteger

Returns:

  • (Integer)


17
18
19
# File 'lib/biryani/frame/priority.rb', line 17

def length
  5
end

#to_binary_sString

Returns:

  • (String)


22
23
24
25
26
27
# File 'lib/biryani/frame/priority.rb', line 22

def to_binary_s
  payload_length = length
  flags = 0x00

  Frame.to_binary_s_header(payload_length, @f_type, flags, @stream_id) + [@stream_dependency, @weight].pack('NC')
end