module BSON::Array::ClassMethods

def from_bson(buffer, **options)

Other tags:
    See: http://bsonspec.org/#/specification -

Returns:
  • (Array) - The decoded array.

Options Hash: (**options)
  • :mode (nil | :bson) -- Decoding mode to use.

Parameters:
  • buffer (ByteBuffer) -- The byte buffer.

Other tags:
    Note: - If the argument cannot be parsed, an exception will be raised
def from_bson(buffer, **options)
  if buffer.respond_to?(:get_array)
    buffer.get_array(**options)
  else
    parse_array_from_buffer(buffer, **options)
  end
end

def parse_array_elements_from_buffer(array, buffer, **options)

Parameters:
  • options (Hash) -- the optional keyword arguments
  • buffer (ByteBuf) -- the buffer to read from
  • array (Array) -- the array to populate
def parse_array_elements_from_buffer(array, buffer, **options)
  while (type = buffer.get_byte) != NULL_BYTE
    buffer.get_cstring
    cls = BSON::Registry.get(type)
    value = if options.empty?
              cls.from_bson(buffer)
            else
              cls.from_bson(buffer, **options)
            end
    array << value
  end
end

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