diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-08-11 22:49:27 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-08-11 22:49:40 +0900 |
commit | 704bb504415df1d46b322054e433c4035701acc3 (patch) | |
tree | 94c650070caa5acc1da42f3653bde69c50888483 | |
parent | 72c5c49fa5a5f58d9bb0f87e5f6ed80bbd8c5492 (diff) | |
download | plum-704bb504415df1d46b322054e433c4035701acc3.tar.gz |
frame_utils: simplify split_* by mutating Frame object
-rw-r--r-- | lib/plum/frame_utils.rb | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/lib/plum/frame_utils.rb b/lib/plum/frame_utils.rb index 66be18d..69ae3d2 100644 --- a/lib/plum/frame_utils.rb +++ b/lib/plum/frame_utils.rb @@ -11,13 +11,9 @@ module Plum raise "Frame type must be DATA" unless self.type == :data fragments = self.payload.each_byteslice(max).to_a - - frames = [] - last = Frame.data(stream_id, fragments.pop, *(self.flags & [:end_stream])) - fragments.each do |fragment| - frames << Frame.data(stream_id, fragment, *(self.flags - [:end_stream])) - end - frames << last + 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 @@ -30,16 +26,10 @@ module Plum 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 = [] - frames << Frame.new(type_value: self.type_value, flags: self.flags - [:end_headers], stream_id: self.stream_id, payload: fragments.shift) - if fragments.size > 0 - last = Frame.continuation(stream_id, fragments.pop, *(self.flags & [:end_headers])) - fragments.each do |fragment| - frames << Frame.continuation(stream_id, fragment) - end - frames << last - end + 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 |