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.
-
#ktime_ns ⇒ Object
Returns the value of attribute ktime_ns.
-
#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
42 43 44 |
# File 'lib/vivarium.rb', line 42 def event_name @event_name end |
#ktime_ns ⇒ Object
Returns the value of attribute ktime_ns
42 43 44 |
# File 'lib/vivarium.rb', line 42 def ktime_ns @ktime_ns end |
#payload ⇒ Object
Returns the value of attribute payload
42 43 44 |
# File 'lib/vivarium.rb', line 42 def payload @payload end |
#pid ⇒ Object
Returns the value of attribute pid
42 43 44 |
# File 'lib/vivarium.rb', line 42 def pid @pid end |
Class Method Details
.c_string(bytes) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/vivarium.rb', line 64 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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/vivarium.rb', line 47 def self.from_binary(raw) bytes = raw.to_s.b bytes = bytes.ljust(EVENT_STRUCT_SIZE, "\x00") ktime_ns = bytes[EVENT_TS_OFFSET, EVENT_TS_SIZE].unpack1("Q<") pid = bytes[EVENT_PID_OFFSET, 4].unpack1("L<") event_name = c_string(bytes[EVENT_NAME_OFFSET, EVENT_NAME_SIZE]) raw_payload = bytes[EVENT_PAYLOAD_OFFSET, EVENT_PAYLOAD_SIZE] payload = if %w[dns_req sock_connect odd_socket].include?(event_name) raw_payload else c_string(raw_payload) end new(ktime_ns: ktime_ns, pid: pid, event_name: event_name, payload: payload) end |
Instance Method Details
#empty? ⇒ Boolean
43 44 45 |
# File 'lib/vivarium.rb', line 43 def empty? ktime_ns.to_i.zero? && pid.to_i.zero? && event_name.to_s.empty? && payload.to_s.empty? end |