module BSON::Hash::ClassMethods

Public Instance Methods

from_bson(buffer) click to toggle source

Deserialize the hash from BSON.

@param [ ByteBuffer ] buffer The byte buffer.

@return [ Array ] The decoded hash.

@see bsonspec.org/#/specification

@since 2.0.0

# File lib/bson/hash.rb, line 79
def from_bson(buffer)
  if buffer.respond_to?(:get_hash)
    buffer.get_hash
  else
    hash = Document.allocate
    buffer.get_int32 # Throw away the size.
    while (type = buffer.get_byte) != NULL_BYTE
      field = buffer.get_cstring
      hash.store(field, BSON::Registry.get(type, field).from_bson(buffer))
    end
    hash
  end
end