Method: OpenC3::BinaryAccessor.check_bounds_and_buffer_size

Defined in:
lib/openc3/accessors/binary_accessor.rb

.check_bounds_and_buffer_size(bit_offset, bit_size, buffer_length, endianness, data_type) ⇒ Object

Calculate the bounds of the string to access the item based on the bit_offset and bit_size. Also determine if the buffer size is sufficient.



777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
# File 'lib/openc3/accessors/binary_accessor.rb', line 777

def self.check_bounds_and_buffer_size(bit_offset, bit_size, buffer_length, endianness, data_type)
  result = true # Assume ok

  # Define bounds of string to access this item
  lower_bound = bit_offset / 8
  upper_bound = (bit_offset + bit_size - 1) / 8

  # Sanity check buffer size
  if upper_bound >= buffer_length
    # If it's not the special case of little endian bit field then we fail and return false
    if !((endianness == :LITTLE_ENDIAN) &&
           ((data_type == :INT) || (data_type == :UINT)) &&
           # Not byte aligned with an even bit size
           (!((byte_aligned(bit_offset)) && (even_bit_size(bit_size)))) &&
           (lower_bound < buffer_length)
        )
      result = false
    end
  end
  return result, lower_bound, upper_bound
end