Class: Kamerling::Message
- Inherits:
-
Object
- Object
- Kamerling::Message
- Defined in:
- lib/kamerling/message.rb
Constant Summary collapse
- KNOWN_TYPES =
%i(DATA PING RGST RSLT)
- UnknownType =
Class.new(RuntimeError)
Class Method Summary collapse
Instance Method Summary collapse
- #client_type ⇒ Object
- #client_uuid ⇒ Object
-
#initialize(raw) ⇒ Message
constructor
A new instance of Message.
- #payload ⇒ Object
- #project_uuid ⇒ Object
- #task_uuid ⇒ Object
- #to_hex ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(raw) ⇒ Message
Returns a new instance of Message.
20 21 22 23 |
# File 'lib/kamerling/message.rb', line 20 def initialize(raw) @raw = raw fail UnknownType, type unless KNOWN_TYPES.include?(type) or type.empty? end |
Class Method Details
.build(client:, payload:, project:, task:, type:) ⇒ Object
11 12 13 14 |
# File 'lib/kamerling/message.rb', line 11 def self.build(client:, payload:, project:, task:, type:) new([type, "\0\0\0\0\0\0\0\0\0\0\0\0", UUID.bin(client.uuid), UUID.bin(project.uuid), UUID.bin(task.uuid), payload].join) end |
.parse(raw) ⇒ Object
16 17 18 |
# File 'lib/kamerling/message.rb', line 16 def self.parse(raw) new(raw) end |
Instance Method Details
#client_type ⇒ Object
25 26 27 |
# File 'lib/kamerling/message.rb', line 25 def client_type raw[4..7].to_sym end |
#client_uuid ⇒ Object
29 30 31 |
# File 'lib/kamerling/message.rb', line 29 def client_uuid UUID[raw[16..31]] end |
#payload ⇒ Object
33 34 35 |
# File 'lib/kamerling/message.rb', line 33 def payload raw[64..-1] end |
#project_uuid ⇒ Object
37 38 39 |
# File 'lib/kamerling/message.rb', line 37 def project_uuid UUID[raw[32..47]] end |
#task_uuid ⇒ Object
41 42 43 |
# File 'lib/kamerling/message.rb', line 41 def task_uuid UUID[raw[48..63]] end |
#to_hex ⇒ Object
45 46 47 |
# File 'lib/kamerling/message.rb', line 45 def to_hex raw.unpack('H*').first.scan(/../).join(' ') end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/kamerling/message.rb', line 49 def to_s raw end |
#type ⇒ Object
53 54 55 |
# File 'lib/kamerling/message.rb', line 53 def type raw[0..3].to_sym end |