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
# 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
      if value
        if not Array === value
          value_temp = []
          value_temp << value
          value = value_temp
        end
        value << ary_value
      else
        value = ary_value
      end
    end
  end
  return value
end

.write_item(item, value, buffer) ⇒ Object



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

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 enfore that COSMOS DERIVED items must have a write_conversion to be written



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

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



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

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



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

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



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

def enforce_short_buffer_allowed
  return true
end