module BSON::Array::ClassMethods

def parse_array_from_buffer(buffer, **options)

Raises:
  • (BSON::Error::BSONDecodeError) - if the expected number of

Returns:
  • (Array) - the array that was parsed

Parameters:
  • options (Hash) -- the optional keyword arguments
  • buffer (ByteBuf) -- the buffer to read from
def parse_array_from_buffer(buffer, **options)
  new.tap do |array|
    start_position = buffer.read_position
    expected_byte_size = buffer.get_int32
    parse_array_elements_from_buffer(array, buffer, **options)
    actual_byte_size = buffer.read_position - start_position
    if actual_byte_size != expected_byte_size
      raise Error::BSONDecodeError,
            "Expected array to take #{expected_byte_size} bytes but it took #{actual_byte_size} bytes"
    end
  end
end