Method: Cosmos::Structure#write_item

Defined in:
lib/cosmos/packets/structure.rb

#write_item(item, value, value_type = :RAW, buffer = @buffer) ⇒ Object

Write a value to the buffer based on the item definition

Parameters:

  • item (StructureItem)

    Instance of StructureItem or one of its subclasses

  • value (Object)

    Value based on the item definition. This could be a string, integer, float, or array of values.

  • value_type (Symbol) (defaults to: :RAW)

    Not used. Subclasses should overload this parameter to check whether to perform conversions on the item.

  • buffer (String) (defaults to: @buffer)

    The binary buffer to write the value to



349
350
351
352
353
354
355
356
# File 'lib/cosmos/packets/structure.rb', line 349

def write_item(item, value, value_type = :RAW, buffer = @buffer)
  buffer = allocate_buffer_if_needed() unless buffer
  if item.array_size
    BinaryAccessor.write_array(value, item.bit_offset, item.bit_size, item.data_type, item.array_size, buffer, item.endianness, item.overflow)
  else
    BinaryAccessor.write(value, item.bit_offset, item.bit_size, item.data_type, buffer, item.endianness, item.overflow)
  end
end