class GMSEC::Message
Public Instance Methods
<<(data)
click to toggle source
# File lib/gmsec/message.rb, line 113 def <<(data) # We can append a single Field or multiple fields encapsulated as a Hash. if data.is_a? GMSEC::Field gmsec_MsgAddField(self, data, status) elsif data.is_a? Hash data.each do |key, value| self << GMSEC::Field.new(key, value) end elsif data raise TypeError.new("#{data.class} is not supported as a GMSEC field type.") end if status.is_error? raise RuntimeError.new("Error adding data to message: #{status}") end end
[](name)
click to toggle source
# File lib/gmsec/message.rb, line 97 def [](name) field = GMSEC::Field.new gmsec_MsgGetField(self, name.to_s, field, status) case status.code when GMSEC_STATUS_NO_ERROR field.value when !GMSEC_INVALID_FIELD_NAME raise RuntimeError.new("Error getting message field: #{status}") end end
[]=(name, value)
click to toggle source
# File lib/gmsec/message.rb, line 109 def []=(name, value) self << GMSEC::Field.new(name, value) end
clear_field(name)
click to toggle source
# File lib/gmsec/message.rb, line 89 def clear_field(name) gmsec_MsgClearField(self, name.to_s, status) if status.is_error? raise RuntimeError.new("Error clearing message field: #{status}") end end
clear_fields()
click to toggle source
# File lib/gmsec/message.rb, line 81 def clear_fields gmsec_MsgClearFields(self, status) if status.is_error? raise RuntimeError.new("Error clearing message fields: #{status}") end end
config=(config)
click to toggle source
# File lib/gmsec/message.rb, line 73 def config=(config) gmsec_MsgSetConfig(self, config, status) if status.is_error? raise RuntimeError.new("Error setting message config: #{status}") end end
fields()
click to toggle source
# File lib/gmsec/message.rb, line 136 def fields Enumerator.new do |y| field = GMSEC::Field.new gmsec_MsgGetFirstField(self, field, status) while status.code != GMSEC_FIELDS_END_REACHED && status.code == GMSEC_STATUS_NO_ERROR y << field gmsec_MsgGetNextField(self, field, status) end unless status.code == GMSEC_FIELDS_END_REACHED raise RuntimeError.new("Error reading message fields: #{status}") end end end
from_xml(xml)
click to toggle source
# File lib/gmsec/message.rb, line 170 def from_xml(xml) gmsec_MsgFromXML(self, xml, status).tap do |_| if status.is_error? raise RuntimeError.new("Error converting xml to message: #{status}") end end end
length()
click to toggle source
# File lib/gmsec/message.rb, line 130 def length pointer = FFI::MemoryPointer.new(find_type(:GMSEC_I32)) gmsec_MsgGetFieldCount(self, pointer, status) pointer.read_int32 end
load_fields_from_config_file(config_file, message_name)
click to toggle source
# File lib/gmsec/message.rb, line 8 def load_fields_from_config_file(config_file, message_name) config_file.get_message(message_name, message: self) end
size()
click to toggle source
# File lib/gmsec/message.rb, line 178 def size pointer = FFI::MemoryPointer.new(find_type(:GMSEC_U32)) gmsec_MsgGetSize(self, pointer, status) pointer.read_uint32 end
subject()
click to toggle source
# File lib/gmsec/message.rb, line 55 def subject with_string_pointer do |pointer| gmsec_GetMsgSubject(self, pointer, status) if status.is_error? raise RuntimeError.new("Error getting message subject: #{status}") end end end
subject=(subject)
click to toggle source
# File lib/gmsec/message.rb, line 65 def subject=(subject) gmsec_SetMsgSubject(self, subject, status) if status.is_error? raise RuntimeError.new("Error setting message subject: #{status}") end end
time()
click to toggle source
# File lib/gmsec/message.rb, line 184 def time gmsec_MsgGetTime end
to_h()
click to toggle source
# File lib/gmsec/message.rb, line 156 def to_h Hash[fields.map{|field| [field.name, field.value]}] end
to_s()
click to toggle source
# File lib/gmsec/message.rb, line 152 def to_s ::Terminal::Table.new(title: subject, rows: to_h) end
to_xml()
click to toggle source
# File lib/gmsec/message.rb, line 160 def to_xml with_string_pointer do |pointer| gmsec_MsgToXML(self, pointer, status) if status.is_error? raise RuntimeError.new("Error converting message to xml: #{status}") end end end
type()
click to toggle source
# File lib/gmsec/message.rb, line 12 def type pointer = FFI::MemoryPointer.new(find_type(:GMSEC_MSG_KIND)) gmsec_GetMsgKind(self, pointer, status) if status.is_error? raise RuntimeError.new("Error getting message type: #{status}") end case pointer.read_ushort when GMSEC_MSG_PUBLISH :publish when GMSEC_MSG_REPLY :reply when GMSEC_MSG_REQUEST :request when GMSEC_MSG_UNSET :unset else raise TypeError.new("Unrecognized GMSEC data type") end end
type=(type)
click to toggle source
# File lib/gmsec/message.rb, line 34 def type=(type) value = case type when :publish GMSEC_MSG_PUBLISH when :reply GMSEC_MSG_REPLY when :request GMSEC_MSG_REQUEST when :unset GMSEC_MSG_REQUEST else raise TypeError.new("#{type} is not supported as a GMSEC type.") end gmsec_SetMsgKind(self, value, status) if status.is_error? raise RuntimeError.new("Error setting message type: #{status}") end end
valid?()
click to toggle source
# File lib/gmsec/message.rb, line 188 def valid? gmsec_isMsgValid(self) == self.class.enum_type(:GMSEC_BOOL)[:GMSEC_TRUE] end