Module: Arf::Wire
- Defined in:
- lib/arf/wire/frame.rb,
lib/arf/wire/client.rb,
lib/arf/wire/errors.rb,
lib/arf/wire/server.rb,
lib/arf/wire/stream.rb,
lib/arf/wire/encoding.rb,
lib/arf/wire/error_code.rb,
lib/arf/wire/frame_kind.rb,
lib/arf/wire/server/peer.rb,
lib/arf/wire/wait_signal.rb,
lib/arf/wire/frame_reader.rb,
lib/arf/wire/stream/state.rb,
lib/arf/wire/base_connection.rb,
lib/arf/wire/frames/base_frame.rb,
lib/arf/wire/frames/data_frame.rb,
lib/arf/wire/frames/ping_frame.rb,
lib/arf/wire/frames/go_away_frame.rb,
lib/arf/wire/frames/make_stream_frame.rb,
lib/arf/wire/frames/reset_stream_frame.rb,
lib/arf/wire/frames/configuration_frame.rb
Defined Under Namespace
Classes: BaseConnection, BaseFrame, Client, ClosedStreamError, ConfigurationFrame, ConnectionResetError, DataFrame, Frame, FrameMismatchError, FrameReader, GoAwayFrame, InvalidFrameError, InvalidFrameLengthError, MagicNumberMismatchError, MakeStreamFrame, PingFrame, ResetStreamFrame, Server, Stream, StreamCanceledError, StreamResetError, UnexpectedAssociatedFrameError, UnexpectedUnassociatedFrameError, UnknownFrameKindError, WaitSignal, WireError
Constant Summary
collapse
- MAX_PAYLOAD =
65_535
- ERROR_CODE_NO_ERROR =
0x00
- ERROR_CODE_PROTOCOL_ERROR =
0x01
- ERROR_CODE_INTERNAL_ERROR =
0x02
- ERROR_CODE_STREAM_CLOSED =
0x03
- ERROR_CODE_FRAME_SIZE_ERROR =
0x04
- ERROR_CODE_REFUSED_STREAM =
0x05
- ERROR_CODE_CANCEL =
0x06
- ERROR_CODE_COMPRESSION_ERROR =
0x07
- ERROR_CODE_ENHANCE_YOUR_CALM =
0x08
- ERROR_CODE_INADEQUATE_SECURITY =
0x09
- ERROR_TO_STRING =
{
ERROR_CODE_NO_ERROR => "No error",
ERROR_CODE_PROTOCOL_ERROR => "Protocol Error",
ERROR_CODE_INTERNAL_ERROR => "Internal Error",
ERROR_CODE_STREAM_CLOSED => "Stream Closed",
ERROR_CODE_FRAME_SIZE_ERROR => "Frame Size Error",
ERROR_CODE_REFUSED_STREAM => "Refused Stream",
ERROR_CODE_CANCEL => "Cancel",
ERROR_CODE_COMPRESSION_ERROR => "Compression Error",
ERROR_CODE_ENHANCE_YOUR_CALM => "Enhance Your Calm",
ERROR_CODE_INADEQUATE_SECURITY => "Inadequate Security"
}.freeze
- FRAME_KIND_CONFIGURATION =
0x0
- FRAME_KIND_PING =
0x1
- FRAME_KIND_GO_AWAY =
0x2
- FRAME_KIND_MAKE_STREAM =
0x3
- FRAME_KIND_RESET_STREAM =
0x4
- FRAME_KIND_DATA =
0x5
- FRAME_TO_SYMBOL =
{
FRAME_KIND_CONFIGURATION => :configuration,
FRAME_KIND_PING => :ping,
FRAME_KIND_GO_AWAY => :go_away,
FRAME_KIND_MAKE_STREAM => :make_stream,
FRAME_KIND_RESET_STREAM => :reset_stream,
FRAME_KIND_DATA => :data
}.freeze
- SYMBOL_TO_FRAME =
FRAME_TO_SYMBOL.to_a.to_h(&:reverse)
Class Method Summary
collapse
Class Method Details
.data_frames_from_buffer(id, buf, end_stream: false) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/arf/wire/encoding.rb', line 12
def self.data_frames_from_buffer(id, buf, end_stream: false)
buf = case buf
when StringIO then buf.string
when String then buf
else buf.to_s
end
len = buf.length
if len <= MAX_PAYLOAD
return [
DataFrame.new do |fr|
fr.stream_id = id
fr.end_data!
fr.end_stream! if end_stream
fr.payload = buf
end
]
end
frames = []
written = 0
loop do
to_write = [len - written, MAX_PAYLOAD].min
end_data = (len - written - to_write).zero?
frames << DataFrame.new do |fr|
fr.stream_id = id
fr.end_data! if end_data
fr.end_stream! if end_stream
fr.payload = buf[written...written + to_write]
end
written += to_write
break if end_data
end
frames
end
|
.decode_uint16(io) ⇒ Object
9
|
# File 'lib/arf/wire/encoding.rb', line 9
def self.decode_uint16(io) = io.read(2).unpack1("S>")
|
.decode_uint32(io) ⇒ Object
10
|
# File 'lib/arf/wire/encoding.rb', line 10
def self.decode_uint32(io) = io.read(4).unpack1("L>")
|
.encode_uint16(v) ⇒ Object
7
|
# File 'lib/arf/wire/encoding.rb', line 7
def self.encode_uint16(v) = [v].pack("S>")
|
.encode_uint32(v) ⇒ Object
8
|
# File 'lib/arf/wire/encoding.rb', line 8
def self.encode_uint32(v) = [v].pack("L>")
|
.error_code_to_string(code) ⇒ Object
29
30
31
32
33
|
# File 'lib/arf/wire/error_code.rb', line 29
def self.error_code_to_string(code)
return ERROR_TO_STRING[code] if ERROR_TO_STRING.key? code
"Unknown error 0x#{code.to_s(16)}"
end
|