Class: OpenC3::FormAccessor

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

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, read_items, #write_item, write_items, #write_items

Constructor Details

This class inherits a constructor from OpenC3::Accessor

Class Method Details

.read_item(item, buffer) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/openc3/accessors/form_accessor.rb', line 24

def self.read_item(item, buffer)
  ary = URI.decode_www_form(buffer)
  value = nil
  ary.each do |key, ary_value|
    if key == item.key
      # Handle the case of multiple values for the same key
      # and build up an array of values
      if value
        # Second time through value is not an Array yet
        if not Array === value
          value = [value]
        end
        value << ary_value
      else
        value = ary_value
      end
    end
  end
  return value
end

.write_item(item, value, buffer) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/openc3/accessors/form_accessor.rb', line 45

def self.write_item(item, value, buffer)
  ary = URI.decode_www_form(buffer)

  # Remove existing item and bad keys from array
  ary.reject! {|key, _ary_value| (key == item.key) or (key.to_s[0] == "\u0000")}

  if Array === value
    value.each do |value_value|
      ary << [item.key, value_value]
    end
  else
    ary << [item.key, value]
  end

  buffer.replace(URI.encode_www_form(ary))
  return value
end

Instance Method Details

#enforce_derived_write_conversion(_item) ⇒ Object

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



85
86
87
# File 'lib/openc3/accessors/form_accessor.rb', line 85

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



65
66
67
# File 'lib/openc3/accessors/form_accessor.rb', line 65

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



72
73
74
# File 'lib/openc3/accessors/form_accessor.rb', line 72

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



79
80
81
# File 'lib/openc3/accessors/form_accessor.rb', line 79

def enforce_short_buffer_allowed
  return true
end