Module: BSON::Hash
- Defined in:
- lib/bson/hash.rb
Overview
Injects behaviour for encoding and decoding hashes to and from raw bytes as specified by the BSON spec.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- BSON_TYPE =
A hash, also called an embedded document, is type 0x03 in the BSON spec.
::String.new(3.chr, encoding: BINARY).freeze
Instance Method Summary collapse
-
#as_extended_json(**options) ⇒ Hash
Converts this object to a representation directly serializable to Extended JSON (github.com/mongodb/specifications/blob/master/source/extended-json/extended-json.md).
-
#to_bson(buffer = ByteBuffer.new) ⇒ BSON::ByteBuffer
Get the hash as encoded BSON.
-
#to_bson_normalized_value ⇒ BSON::Document
Converts the hash to a normalized value in a BSON document.
Instance Method Details
#as_extended_json(**options) ⇒ Hash
Converts this object to a representation directly serializable to Extended JSON (github.com/mongodb/specifications/blob/master/source/extended-json/extended-json.md).
This method recursively invokes as_extended_json
with the provided options on each hash value.
65 66 67 |
# File 'lib/bson/hash.rb', line 65 def as_extended_json(**) transform_values { |value| value.as_extended_json(**) } end |
#to_bson(buffer = ByteBuffer.new) ⇒ BSON::ByteBuffer
Get the hash as encoded BSON.
35 36 37 38 39 40 41 42 43 |
# File 'lib/bson/hash.rb', line 35 def to_bson(buffer = ByteBuffer.new) # If the native buffer version has an optimized version, we'll call # it directly. Otherwise, we'll serialize the hash the hard way. if buffer.respond_to?(:put_hash) buffer.put_hash(self) else serialize_to_buffer(buffer) end end |
#to_bson_normalized_value ⇒ BSON::Document
Converts the hash to a normalized value in a BSON document.
51 52 53 |
# File 'lib/bson/hash.rb', line 51 def to_bson_normalized_value Document.new(self) end |