Module: BSON::Hash::ClassMethods

Defined in:
lib/bson/hash.rb

Overview

Since:

  • 2.0.0

Instance Method Summary collapse

Instance Method Details

#from_bson(bson) ⇒ Array

Deserialize the hash from BSON.

Parameters:

  • bson (IO)

    The bson representing a hash.

Returns:

  • (Array)

    The decoded hash.

See Also:

Since:

  • 2.0.0



74
75
76
77
78
79
80
81
82
# File 'lib/bson/hash.rb', line 74

def from_bson(bson)
  hash = new
  bson.read(4) # Swallow the first four bytes.
  while (type = bson.readbyte.chr) != NULL_BYTE
    field = bson.gets(NULL_BYTE).from_bson_string.chop!
    hash[field] = BSON::Registry.get(type).from_bson(bson)
  end
  hash
end