Class: NNQ::Zstd::Wrapper
- Inherits:
-
Object
- Object
- NNQ::Zstd::Wrapper
show all
- Defined in:
- lib/nnq/zstd/wrapper.rb
Overview
Socket decorator that transparently runs every outbound body through the Codec’s encoder and every inbound wire message through its decoder. Delegates any unknown method to the wrapped socket, so the wrapper quacks like an ‘NNQ::Socket`.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(socket, level:, dicts:) ⇒ Wrapper
Returns a new instance of Wrapper.
13
14
15
16
17
18
19
20
21
|
# File 'lib/nnq/zstd/wrapper.rb', line 13
def initialize(socket, level:, dicts:)
@sock = socket
@codec = Codec.new(
level: level,
dicts: dicts,
recv_max_size: recv_max_size_from(socket),
)
start_dict_monitor!
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **kwargs, &block) ⇒ Object
71
72
73
74
75
76
77
|
# File 'lib/nnq/zstd/wrapper.rb', line 71
def method_missing(name, *args, **kwargs, &block)
if @sock.respond_to?(name)
@sock.public_send(name, *args, **kwargs, &block)
else
super
end
end
|
Instance Attribute Details
#codec ⇒ Object
Returns the value of attribute codec.
10
11
12
|
# File 'lib/nnq/zstd/wrapper.rb', line 10
def codec
@codec
end
|
Instance Method Details
#close ⇒ Object
56
57
58
59
60
61
62
63
|
# File 'lib/nnq/zstd/wrapper.rb', line 56
def close
begin
@monitor_task&.stop
rescue StandardError
end
@sock.close
end
|
#receive ⇒ Object
Loops internally until a real payload arrives or the socket closes. Dict frames are silently installed and discarded.
46
47
48
49
50
51
52
53
|
# File 'lib/nnq/zstd/wrapper.rb', line 46
def receive
loop do
raw = @sock.receive
return raw if raw.nil?
decoded = @codec.decode(raw)
return decoded unless decoded.nil?
end
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
66
67
68
|
# File 'lib/nnq/zstd/wrapper.rb', line 66
def respond_to_missing?(name, include_private = false)
@sock.respond_to?(name, include_private)
end
|
#send(body) ⇒ Object
24
25
26
|
# File 'lib/nnq/zstd/wrapper.rb', line 24
def send(body)
send_with_codec(body) { |wire| @sock.send(wire) }
end
|
#send_reply(body) ⇒ Object
29
30
31
|
# File 'lib/nnq/zstd/wrapper.rb', line 29
def send_reply(body)
send_with_codec(body) { |wire| @sock.send_reply(wire) }
end
|
#send_request(body) ⇒ Object
39
40
41
|
# File 'lib/nnq/zstd/wrapper.rb', line 39
def send_request(body)
send_with_codec(body) { |wire| @sock.send_request(wire) }
end
|
#send_survey(body) ⇒ Object
34
35
36
|
# File 'lib/nnq/zstd/wrapper.rb', line 34
def send_survey(body)
send_with_codec(body) { |wire| @sock.send_survey(wire) }
end
|