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
23 24 25 |
# File 'lib/vivarium.rb', line 23 def event_name @event_name end |
#payload ⇒ Object
Returns the value of attribute payload
23 24 25 |
# File 'lib/vivarium.rb', line 23 def payload @payload end |
#pid ⇒ Object
Returns the value of attribute pid
23 24 25 |
# File 'lib/vivarium.rb', line 23 def pid @pid end |
Class Method Details
.from_binary(raw) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vivarium.rb', line 28 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 = bytes[4, EVENT_NAME_SIZE].delete("\x00") payload = bytes[4 + EVENT_NAME_SIZE, EVENT_PAYLOAD_SIZE].delete("\x00") new(pid: pid, event_name: event_name, payload: payload) end |
Instance Method Details
#empty? ⇒ Boolean
24 25 26 |
# File 'lib/vivarium.rb', line 24 def empty? pid.to_i.zero? && event_name.to_s.empty? && payload.to_s.empty? end |