Module: BSON::Symbol
- Defined in:
- lib/bson/symbol.rb
Overview
Symbols are deprecated in the BSON spec, but they are still currently supported here for backwards compatibility.
Injects behaviour for encoding and decoding symbol values to and from raw bytes as specified by the BSON spec.
Defined Under Namespace
Modules: ClassMethods Classes: Raw
Constant Summary collapse
- BSON_TYPE =
A symbol is type 0x0E in the BSON spec.
::String.new(14.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).
-
#bson_type ⇒ String
Symbols are serialized as strings as symbols are now removed from the BSON specification.
-
#to_bson(buffer = ByteBuffer.new) ⇒ BSON::ByteBuffer
Get the symbol as encoded BSON.
-
#to_bson_key ⇒ String
Get the symbol as a BSON key name encoded C symbol.
-
#to_bson_normalized_key ⇒ String
Converts the symbol to a normalized key 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).
95 96 97 |
# File 'lib/bson/symbol.rb', line 95 def as_extended_json(**) { "$symbol" => to_s } end |
#bson_type ⇒ String
Symbols are serialized as strings as symbols are now removed from the BSON specification. Therefore the bson_type when serializing must be a string.
47 48 49 |
# File 'lib/bson/symbol.rb', line 47 def bson_type String::BSON_TYPE end |
#to_bson(buffer = ByteBuffer.new) ⇒ BSON::ByteBuffer
Get the symbol as encoded BSON.
61 62 63 |
# File 'lib/bson/symbol.rb', line 61 def to_bson(buffer = ByteBuffer.new) buffer.put_symbol(self) end |
#to_bson_key ⇒ String
Get the symbol as a BSON key name encoded C symbol.
75 76 77 |
# File 'lib/bson/symbol.rb', line 75 def to_bson_key self end |
#to_bson_normalized_key ⇒ String
Converts the symbol to a normalized key in a BSON document.
87 88 89 |
# File 'lib/bson/symbol.rb', line 87 def to_bson_normalized_key to_s end |