Class: Vivarium::Event
- Inherits:
-
Struct
- Object
- Struct
- Vivarium::Event
- Defined in:
- lib/vivarium.rb
Instance Attribute Summary collapse
-
#event_name ⇒ Object
Returns the value of attribute event_name.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#pid ⇒ Object
Returns the value of attribute pid.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#event_name ⇒ Object
Returns the value of attribute event_name
36 37 38 |
# File 'lib/vivarium.rb', line 36 def event_name @event_name end |
#payload ⇒ Object
Returns the value of attribute payload
36 37 38 |
# File 'lib/vivarium.rb', line 36 def payload @payload end |
#pid ⇒ Object
Returns the value of attribute pid
36 37 38 |
# File 'lib/vivarium.rb', line 36 def pid @pid end |
Class Method Details
.c_string(bytes) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/vivarium.rb', line 52 def self.c_string(bytes) str = bytes.to_s.b nul = str.index("\x00") return str if nul.nil? str[0, nul] end |
.from_binary(raw) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/vivarium.rb', line 41 def self.from_binary(raw) bytes = raw.to_s.b bytes = bytes.ljust(EVENT_STRUCT_SIZE, "\x00") pid = bytes[0, 4].unpack1("L<") event_name = c_string(bytes[4, EVENT_NAME_SIZE]) payload = c_string(bytes[4 + EVENT_NAME_SIZE, EVENT_PAYLOAD_SIZE]) new(pid: pid, event_name: event_name, payload: payload) end |
Instance Method Details
#empty? ⇒ Boolean
37 38 39 |
# File 'lib/vivarium.rb', line 37 def empty? pid.to_i.zero? && event_name.to_s.empty? && payload.to_s.empty? end |