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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/openc3/accessors/form_accessor.rb', line 19

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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/openc3/accessors/form_accessor.rb', line 40

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



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

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



60
61
62
# File 'lib/openc3/accessors/form_accessor.rb', line 60

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



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

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. Items outside the buffer bounds will return nil when read.



74
75
76
# File 'lib/openc3/accessors/form_accessor.rb', line 74

def enforce_short_buffer_allowed
  return true
end