module BSON::Array
def as_extended_json(**options)
-
(Array)
- This array converted to extended json representation.
Options Hash:
(**opts)
-
:mode
(nil | :relaxed | :legacy
) -- Serialization mode
def as_extended_json(**options) map do |item| item.as_extended_json(**options) end end
def to_bson(buffer = ByteBuffer.new)
- Since: - 2.0.0
Other tags:
- See: http://bsonspec.org/#/specification -
Returns:
-
(BSON::ByteBuffer)
- The buffer with the encoded object.
Other tags:
- Note: - Arrays are encoded as documents, where the index of the value in
Other tags:
- Example: Get the array as encoded BSON. -
def to_bson(buffer = ByteBuffer.new) if buffer.respond_to?(:put_array) buffer.put_array(self) else position = buffer.length buffer.put_int32(0) each_with_index do |value, index| unless value.respond_to?(:bson_type) raise Error::UnserializableClass, "Array element at position #{index} does not define its BSON serialized type: #{value}" end buffer.put_byte(value.bson_type) buffer.put_cstring(index.to_s) value.to_bson(buffer) end buffer.put_byte(NULL_BYTE) buffer.replace_int32(position, buffer.length - position) end end
def to_bson_normalized_value
- Since: - 3.0.0
Returns:
-
(Array)
- The normalized array.
Other tags:
- Example: Convert the array to a normalized value. -
def to_bson_normalized_value map(&:to_bson_normalized_value) end
def to_bson_object_id
- Since: - 2.0.0
Returns:
-
(String)
- The raw object id bytes.
Raises:
-
(BSON::Error::InvalidObjectId)
- If the array is not 12 elements.
Other tags:
- Note: - This is used for repairing legacy bson data.
Other tags:
- Example: Convert the array to an object id. -
def to_bson_object_id ObjectId.repair(self) { pack('C*') } end