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

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

Constant Summary collapse

MAX_PAYLOAD_LEN =

2^24-1 = 16777215 = 16MB-1

0x00FFFFFF
DEFAULT_PAYLOAD_MAXLEN =

2^14 = 16384 = 16KB

0x00004000
FRAME_HEADER_LEN =
9
NO_ERROR =
0x0
PROTOCOL_ERROR =
0x1
INTERNAL_ERROR =
0x2
FLOW_CONTROL_ERROR =
0x3
SETTINGS_TIMEOUT =
0x4
STREAM_CLOSED =
0x5
FRAME_SIZE_ERROR =
0x6
REFUSED_STREAM =
0x7
CANCEL =
0x8
COMPRESSION_ERROR =
0x9
CONNECT_ERROR =
0xa
ENHANCE_YOUR_CALM =
0xb
INADEQUATE_SECURITY =
0xc
HTTP_1_1_REQUIRED =
0xd

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ H2Packet



51
52
53
54
55
# File 'lib/baykit/bayserver/docker/http/h2/h2_packet.rb', line 51

def initialize(type)
  super(type, FRAME_HEADER_LEN, DEFAULT_PAYLOAD_MAXLEN)
  @flags = H2Flags::FLAGS_NONE
  @stream_id = -1
end

Instance Attribute Details

#flagsObject

Returns the value of attribute flags.



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

def flags
  @flags
end

#stream_idObject

Returns the value of attribute stream_id.



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

def stream_id
  @stream_id
end

Class Method Details

.consolidate_flag_and_int32(flag, val) ⇒ Object



79
80
81
# File 'lib/baykit/bayserver/docker/http/h2/h2_packet.rb', line 79

def self.consolidate_flag_and_int32(flag, val)
  ((flag & 1) << 31) | (val & 0x7FFFFFFF)
end

.extract_flag(val) ⇒ Object



75
76
77
# File 'lib/baykit/bayserver/docker/http/h2/h2_packet.rb', line 75

def self.extract_flag(val)
  (val & 0x80000000) >> 31 & 1
end

.extract_int31(val) ⇒ Object



71
72
73
# File 'lib/baykit/bayserver/docker/http/h2/h2_packet.rb', line 71

def self.extract_int31(val)
  val & 0x7FFFFFFF
end

.make_stream_dependency32(excluded, dep) ⇒ Object



83
84
85
# File 'lib/baykit/bayserver/docker/http/h2/h2_packet.rb', line 83

def self.make_stream_dependency32(excluded, dep)
  (excluded ? 1 : 0) << 31 | extract_int31(dep)
end

Instance Method Details

#pack_headerObject



63
64
65
66
67
68
69
# File 'lib/baykit/bayserver/docker/http/h2/h2_packet.rb', line 63

def pack_header
  acc = new_header_accessor
  put_int24(acc, data_len)
  acc.put_byte(@type)
  acc.put_byte(@flags.flags)
  acc.put_int(H2Packet.extract_int31(stream_id))
end

#put_int24(acc, len) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/baykit/bayserver/docker/http/h2/h2_packet.rb', line 87

def put_int24(acc, len)
  b1 = (len >> 16) & 0xFF
  b2 = (len >> 8) & 0xFF
  b3 = len & 0xFF
  buf = StringUtil.alloc(3)
  buf << b1 << b2 << b3
  acc.put_bytes buf
end

#resetObject



57
58
59
60
61
# File 'lib/baykit/bayserver/docker/http/h2/h2_packet.rb', line 57

def reset
  @flags = H2Flags::FLAGS_NONE
  @stream_id = -1
  super
end

#to_sObject



96
97
98
# File 'lib/baykit/bayserver/docker/http/h2/h2_packet.rb', line 96

def to_s
  "H2Packet(#{@type}) headerLen=#{@header_len} dataLen=#{data_len()} stm=#{@stream_id} flags=#{@flags}"
end