Class: Baykit::BayServer::Docker::Http::H2::H2Packet::H2DataAccessor

Inherits:
PacketPartAccessor
  • Object
show all
Includes:
Baykit::BayServer::Docker::Http::H2::Huffman
Defined in:
lib/baykit/bayserver/docker/http/h2/h2_packet.rb

Instance Method Summary collapse

Constructor Details

#initialize(pkt, start, max_len) ⇒ H2DataAccessor

Returns a new instance of H2DataAccessor.



47
48
49
# File 'lib/baykit/bayserver/docker/http/h2/h2_packet.rb', line 47

def initialize(pkt, start, max_len)
  super
end

Instance Method Details

#get_hpack_int(prefix, head) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/baykit/bayserver/docker/http/h2/h2_packet.rb', line 51

def get_hpack_int(prefix, head)
  max_val = 0xFF >> (8 - prefix)

  first_byte = get_byte
  first_val = first_byte & max_val
  head[0] = first_byte >> prefix
  if first_val != max_val
    first_val
  else
    max_val + get_hpack_int_rest
  end
end

#get_hpack_int_restObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/baykit/bayserver/docker/http/h2/h2_packet.rb', line 64

def get_hpack_int_rest
  rest = 0
  i = 0
  while true
    data = get_byte
    cont = (data & 0x80) != 0
    value = data & 0x7F
    rest = rest + (value << (i*7))
    if !cont
      break
    end
    i += 1
  end
  return rest
end

#get_hpack_stringObject



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/baykit/bayserver/docker/http/h2/h2_packet.rb', line 80

def get_hpack_string
  is_huffman = [nil]
  len = get_hpack_int(7, is_huffman)
  data = StringUtil.alloc(len)
  get_bytes data, 0, len
  if is_huffman[0] == 1
    return HTree.decode(data)
  else
    # ASCII
    return data
  end
end

#put_hpack_int(val, prefix, head) ⇒ Object



93
94
95
96
97
98
99
100
101
102
# File 'lib/baykit/bayserver/docker/http/h2/h2_packet.rb', line 93

def put_hpack_int(val, prefix, head)
  max_val = 0xFF >> (8 -prefix)
  head_val = (head << prefix) & 0xFF
  if val < max_val
    put_byte (val | head_val)
  else
    put_byte (head_val | max_val)
    put_hpack_int_rest(val - max_val)
  end
end

#put_hpack_int_rest(val) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/baykit/bayserver/docker/http/h2/h2_packet.rb', line 104

def put_hpack_int_rest(val)
  while true
    data = val & 0x7F
    next_val = val >> 7
    if next_val == 0
      put_byte(data)
      break
    else
      put_byte(data | 0x80)
      val = next_val
    end
  end
end

#put_hpack_string(value, is_haffman) ⇒ Object



118
119
120
121
122
123
124
125
# File 'lib/baykit/bayserver/docker/http/h2/h2_packet.rb', line 118

def put_hpack_string(value, is_haffman)
  if is_haffman
    raise RuntimeError.new "Illegal State"
  else
    put_hpack_int(value.length, 7, 0)
    put_bytes(value)
  end
end