Module: BSON::Array::ClassMethods

Defined in:
lib/bson/array.rb

Overview

Since:

  • 2.0.0

Instance Method Summary collapse

Instance Method Details

#from_bson(buffer) ⇒ Array

Deserialize the array from BSON.

Parameters:

  • buffer (ByteBuffer)

    The byte buffer.

Returns:

  • (Array)

    The decoded array.

See Also:

Since:

  • 2.0.0



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/bson/array.rb', line 99

def from_bson(buffer)
  if buffer.respond_to?(:get_array)
    buffer.get_array
  else
    array = new
    buffer.get_int32 # throw away the length
    while (type = buffer.get_byte) != NULL_BYTE
      buffer.get_cstring
      array << BSON::Registry.get(type).from_bson(buffer)
    end
    array
  end
end