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 75
def from_bson(buffer)
  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).from_bson(buffer))
  end
  hash
end