Module: BSON::Hash::ClassMethods

Defined in:
lib/bson/hash.rb

Overview

Since:

  • 2.0.0

Instance Method Summary collapse

Instance Method Details

#from_bson(buffer) ⇒ Array

Deserialize the hash from BSON.

Parameters:

Returns:

  • (Array)

    The decoded hash.

See Also:

Since:

  • 2.0.0



79
80
81
82
83
84
85
86
87
88
89
90
91
# 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