Class: OpenC3::XmlAccessor

Inherits:
Accessor show all
Defined in:
lib/openc3/accessors/xml_accessor.rb

Direct Known Subclasses

HtmlAccessor

Instance Attribute Summary

Attributes inherited from Accessor

#packet

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Accessor

#args, convert_to_type, #initialize, #read_item, #read_items, #write_item, #write_items

Constructor Details

This class inherits a constructor from OpenC3::Accessor

Class Method Details

.buffer_to_doc(buffer) ⇒ Object



63
64
65
# File 'lib/openc3/accessors/xml_accessor.rb', line 63

def self.buffer_to_doc(buffer)
  Nokogiri.XML(buffer)
end

.doc_to_buffer(doc) ⇒ Object



67
68
69
# File 'lib/openc3/accessors/xml_accessor.rb', line 67

def self.doc_to_buffer(doc)
  doc.to_xml
end

.read_item(item, buffer) ⇒ Object



24
25
26
27
28
# File 'lib/openc3/accessors/xml_accessor.rb', line 24

def self.read_item(item, buffer)
  return nil if item.data_type == :DERIVED
  doc = buffer_to_doc(buffer)
  return convert_to_type(doc.xpath(item.key).first.to_s, item)
end

.read_items(items, buffer) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/openc3/accessors/xml_accessor.rb', line 39

def self.read_items(items, buffer)
  doc = buffer_to_doc(buffer)
  result = {}
  items.each do |item|
    if item.data_type == :DERIVED
      result[item.name] = nil
    else
      result[item.name] = convert_to_type(doc.xpath(item.key).first.to_s, item)
    end
  end
  return result
end

.write_item(item, value, buffer) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/openc3/accessors/xml_accessor.rb', line 30

def self.write_item(item, value, buffer)
  return nil if item.data_type == :DERIVED
  doc = buffer_to_doc(buffer)
  node = doc.xpath(item.key).first
  node.content = value.to_s
  buffer.replace(doc_to_buffer(doc))
  return value
end

.write_items(items, values, buffer) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/openc3/accessors/xml_accessor.rb', line 52

def self.write_items(items, values, buffer)
  doc = buffer_to_doc(buffer)
  items.each_with_index do |item, index|
    next if item.data_type == :DERIVED
    node = doc.xpath(item.key).first
    node.content = values[index].to_s
  end
  buffer.replace(doc_to_buffer(doc))
  return values
end

Instance Method Details

#enforce_derived_write_conversion(_item) ⇒ Object

If this is true it will enfore that COSMOS DERIVED items must have a write_conversion to be written



93
94
95
# File 'lib/openc3/accessors/xml_accessor.rb', line 93

def enforce_derived_write_conversion(_item)
  return true
end

#enforce_encodingObject

If this is set it will enforce that buffer data is encoded in a specific encoding



73
74
75
# File 'lib/openc3/accessors/xml_accessor.rb', line 73

def enforce_encoding
  return nil
end

#enforce_lengthObject

This affects whether the Packet class enforces the buffer length at all. Set to false to remove any correlation between buffer length and defined sizes of items in COSMOS



80
81
82
# File 'lib/openc3/accessors/xml_accessor.rb', line 80

def enforce_length
  return false
end

#enforce_short_buffer_allowedObject

This sets the short_buffer_allowed flag in the Packet class which allows packets that have a buffer shorter than the defined size. Note that the buffer is still resized to the defined length



87
88
89
# File 'lib/openc3/accessors/xml_accessor.rb', line 87

def enforce_short_buffer_allowed
  return true
end