diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-10-29 14:47:13 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-10-29 14:48:28 +0900 |
commit | b76fb6e5ec81ea9142eb6479a9f05b0b45b75184 (patch) | |
tree | 034853839e2e4ded8c9ed30fb310928175e59e4d | |
parent | beb4306b70e6fe8296fa9f9cc93a179bec3540a4 (diff) | |
download | plum-b76fb6e5ec81ea9142eb6479a9f05b0b45b75184.tar.gz |
hpack/decoder: refactor
-rw-r--r-- | lib/plum/hpack/decoder.rb | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/lib/plum/hpack/decoder.rb b/lib/plum/hpack/decoder.rb index 48546f8..8011967 100644 --- a/lib/plum/hpack/decoder.rb +++ b/lib/plum/hpack/decoder.rb @@ -39,10 +39,9 @@ module Plum def read_integer(str, pos, prefix_length) raise HPACKError.new("integer: end of buffer") if str.empty? - first_byte = str.getbyte(pos) mask = 1 << prefix_length - ret = first_byte % mask + ret = str.getbyte(pos) % mask return [ret, 1] if ret != mask - 1 octets = 0 @@ -105,18 +104,10 @@ module Plum # +---+---------------------------+ # | Value String (Length octets) | # +-------------------------------+ - index, ilen = read_integer(str, pos, 6) - if index == 0 - name, nlen = read_string(str, pos + ilen) - else - name, = fetch(index) - nlen = 0 - end + ret, len = parse_literal(str, pos, 6) + store(*ret) - val, vlen = read_string(str, pos + ilen + nlen) - store(name, val) - - [[name, val], ilen + nlen + vlen] + [ret, len] end def parse_no_indexing(str, pos) @@ -139,7 +130,13 @@ module Plum # +---+---------------------------+ # | Value String (Length octets) | # +-------------------------------+ - index, ilen = read_integer(str, pos, 4) + ret, len = parse_literal(str, pos, 4) + + [ret, len] + end + + def parse_literal(str, pos, pref) + index, ilen = read_integer(str, pos, pref) if index == 0 name, nlen = read_string(str, pos + ilen) else |