Class: ReverseTunnel::Message
- Inherits:
-
Object
- Object
- ReverseTunnel::Message
show all
- Defined in:
- lib/reverse-tunnel/message.rb
Defined Under Namespace
Classes: Data, OpenSession, OpenTunnel, Ping, Unpacker
Constant Summary
collapse
- @@types =
[:open_tunnel, :open_session, :data, :ping]
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.create(type) ⇒ Object
33
34
35
36
|
# File 'lib/reverse-tunnel/message.rb', line 33
def self.create(type)
type = types.at(type) if Fixnum === type
const_get(type.to_s.gsub(/(^|_)(.)/) { $2.capitalize }).new
end
|
.type ⇒ Object
4
5
6
|
# File 'lib/reverse-tunnel/message.rb', line 4
def self.type
name.split("::").last.gsub(/^([A-Z])/) {$1.downcase}.gsub(/([A-Z])/) { "_#{$1.downcase}" }.to_sym
end
|
.type_id ⇒ Object
22
23
24
|
# File 'lib/reverse-tunnel/message.rb', line 22
def self.type_id
types.index(type)
end
|
.types ⇒ Object
12
13
14
|
# File 'lib/reverse-tunnel/message.rb', line 12
def self.types
@@types
end
|
.unpack(data) ⇒ Object
66
67
68
69
70
|
# File 'lib/reverse-tunnel/message.rb', line 66
def self.unpack(data)
Unpacker.new.tap do |packer|
packer.feed data
end.first
end
|
Instance Method Details
#pack ⇒ Object
29
30
31
|
# File 'lib/reverse-tunnel/message.rb', line 29
def pack
[type_id, *payload].to_msgpack
end
|
#type ⇒ Object
7
8
9
|
# File 'lib/reverse-tunnel/message.rb', line 7
def type
self.class.type
end
|
#type_id ⇒ Object
25
26
27
|
# File 'lib/reverse-tunnel/message.rb', line 25
def type_id
self.class.type_id
end
|