123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Protocol::CachingHash Private

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/mongo/protocol/caching_hash.rb

Overview

A Hash that caches the results of #to_bson.

Class Method Summary

Instance Method Summary

Instance Method Details

#bson_type

[ GitHub ]

  
# File 'lib/mongo/protocol/caching_hash.rb', line 30

def bson_type
  Hash::BSON_TYPE
end

#to_bson(buffer = BSON::ByteBuffer.new, validating_keys = nil) ⇒ BSON::ByteBuffer

Caches the result of to_bson and writes it to the given buffer on subsequent calls to this method. If this method is originally called without validation, and then is subsequently called with validation, we will want to recalculate the to_bson to trigger the validations.

Parameters:

  • buffer (BSON::ByteBuffer) (defaults to: BSON::ByteBuffer.new)

    The encoded BSON buffer to append to.

  • validating_keys (true, false) (defaults to: nil)

    Whether keys should be validated when serializing. This option is deprecated and will not be used. It will removed in version 3.0.

Returns:

  • (BSON::ByteBuffer)

    The buffer with the encoded object.

[ GitHub ]

  
# File 'lib/mongo/protocol/caching_hash.rb', line 44

def to_bson(buffer = BSON::ByteBuffer.new, validating_keys = nil)
  if !@bytes
    @bytes = @hash.to_bson(BSON::ByteBuffer.new).to_s
  end
  buffer.put_bytes(@bytes)
end