def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
      if buffer.respond_to?(:put_array)
        buffer.put_array(self, validating_keys)
      else
        position = buffer.length
        buffer.put_int32(0)
        each_with_index do |value, index|
          buffer.put_byte(value.bson_type)
          buffer.put_cstring(index.to_s)
          value.to_bson(buffer, validating_keys)
        end
        buffer.put_byte(NULL_BYTE)
        buffer.replace_int32(position, buffer.length - position)
      end
    end
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
      if buffer.respond_to?(:put_array)
        buffer.put_array(self, validating_keys)
      else
        position = buffer.length
        buffer.put_int32(0)
        each_with_index do |value, index|
          buffer.put_byte(value.bson_type)
          buffer.put_cstring(index.to_s)
          value.to_bson(buffer, validating_keys)
        end
        buffer.put_byte(NULL_BYTE)
        buffer.replace_int32(position, buffer.length - position)
      end
    end
Get the array as encoded BSON.

 @example Get the array as encoded BSON.
   [ 1, 2, 3 ].to_bson

 @note Arrays are encoded as documents, where the index of the value in
   the array is the actual key.

 @return [ BSON::ByteBuffer ] The buffer with the encoded object.

 @see http://bsonspec.org/#/specification

 @since 2.0.0