Method: OpenC3::Structure#initialize

Defined in:
lib/openc3/packets/structure.rb,
ext/openc3/ext/structure/structure.c

#initialize(*args) ⇒ Object

Structure constructor

Parameters:

  • default_endianness (Symbol)

    Must be one of BinaryAccessor::ENDIANNESS. By default it uses BinaryAccessor::HOST_ENDIANNESS to determine the endianness of the host platform.

  • buffer (String)

    Buffer used to store the structure

  • item_class (Class)

    Class used to instantiate new structure items. Must be StructureItem or one of its subclasses.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/openc3/packets/structure.rb', line 75

def initialize(default_endianness = BinaryAccessor::HOST_ENDIANNESS, buffer = nil, item_class = StructureItem)
  if (default_endianness == :BIG_ENDIAN) || (default_endianness == :LITTLE_ENDIAN)
    @default_endianness = default_endianness
    if buffer
      raise TypeError, "wrong argument type #{buffer.class} (expected String)" unless String === buffer

      @buffer = buffer.force_encoding(ASCII_8BIT_STRING)
    else
      @buffer = nil
    end
    @item_class = item_class
    @items = {}
    @sorted_items = []
    @defined_length = 0
    @defined_length_bits = 0
    @pos_bit_size = 0
    @neg_bit_size = 0
    @fixed_size = true
    @short_buffer_allowed = false
    @mutex = nil
    @accessor = BinaryAccessor.new(self)
  else
    raise(ArgumentError, "Unknown endianness '#{default_endianness}', must be :BIG_ENDIAN or :LITTLE_ENDIAN")
  end
end