Method: BSON::Binary.from_vector
- Defined in:
- lib/bson/binary.rb
.from_vector(vector, dtype = nil, padding = 0, validate_vector_data: false) ⇒ BSON::Binary
be ignored when a vector element’s size is less than a byte. Must be 0 if vector is a BSON::Vector.
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/bson/binary.rb', line 412 def self.from_vector(vector, dtype = nil, padding = 0, validate_vector_data: false) data, dtype, padding = extract_args_for_vector(vector, dtype, padding) validate_args_for_vector!(data, dtype, padding) format = case dtype when :int8 then 'c*' when :float32 then 'f*' when :packed_bit then 'C*' else raise ArgumentError, "Unsupported type: #{dtype}" end if validate_vector_data validate_vector_data!(data, dtype) end = [ VECTOR_DATA_TYPES[dtype], padding ].pack('CC') data = data.pack(format) new(.concat(data), :vector) end |