Module: Plum::FrameUtils

Included in:
Frame
Defined in:
lib/plum/frame_utils.rb

Instance Method Summary collapse

Instance Method Details

#parse_settingsHash<Symbol, Integer>

Parses SETTINGS frame payload. Ignores unknown settings type (see RFC7540 6.5.2).

Returns:

  • (Hash<Symbol, Integer>)

    The parsed strings.



36
37
38
39
40
41
42
43
44
45
# File 'lib/plum/frame_utils.rb', line 36

def parse_settings
  settings = {}
  payload.each_byteslice(6) do |param|
    id = param.uint16
    name = Frame::SETTINGS_TYPE.key(id)
    # ignore unknown settings type
    settings[name] = param.uint32(2) if name
  end
  settings
end

#split_data(max) ⇒ Array<Frame>

Splits the DATA frame into multiple frames if the payload size exceeds max size.

Parameters:

  • max (Integer)

    The maximum size of a frame payload.

Returns:

  • (Array<Frame>)

    The splitted frames.



8
9
10
11
12
13
14
15
16
17
# File 'lib/plum/frame_utils.rb', line 8

def split_data(max)
  return [self] if self.length <= max
  raise "Frame type must be DATA" unless self.type == :data

  fragments = self.payload.each_byteslice(max).to_a
  frames = fragments.map {|fragment| Frame.new(type: :data, flags: [], stream_id: self.stream_id, payload: fragment) }
  frames.first.flags = self.flags - [:end_stream]
  frames.last.flags = self.flags & [:end_stream]
  frames
end

#split_headers(max) ⇒ Array<Frame>

Splits the HEADERS or PUSH_PROMISE frame into multiple frames if the payload size exceeds max size.

Parameters:

  • max (Integer)

    The maximum size of a frame payload.

Returns:

  • (Array<Frame>)

    The splitted frames.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/plum/frame_utils.rb', line 22

def split_headers(max)
  return [self] if self.length <= max
  raise "Frame type must be HEADERS or PUSH_PROMISE" unless [:headers, :push_promise].include?(self.type)

  fragments = self.payload.each_byteslice(max).to_a
  frames = fragments.map {|fragment| Frame.new(type: :continuation, flags: [], stream_id: self.stream_id, payload: fragment) }
  frames.first.type_value = self.type_value
  frames.first.flags = self.flags - [:end_headers]
  frames.last.flags = self.flags & [:end_headers]
  frames
end