module BSON::Symbol
Injects behaviour for encoding and decoding symbol values to and from raw bytes as specified by the BSON
spec.
@note Symbols are deprecated in the BSON
spec, but they are still
currently supported here for backwards compatibility.
@see bsonspec.org/#/specification
@since 2.0.0
Constants
- BSON_TYPE
A symbol is type 0x0E in the
BSON
spec.@since 2.0.0
Public Instance Methods
Symbols are serialized as strings as symbols are now removed from the BSON
specification. Therefore the bson_type
when serializing must be a string.
@example Get the BSON
type for the symbol.
:test.bson_type
@return [ String
] The single byte BSON
type.
@see bsonspec.org/#/specification
@since 4.0.0
# File lib/bson/symbol.rb, line 45 def bson_type String::BSON_TYPE end
Get the symbol as encoded BSON
.
@example Get the symbol as encoded BSON
.
:test.to_bson
@return [ BSON::ByteBuffer
] The buffer with the encoded object.
@see bsonspec.org/#/specification
@since 2.0.0
# File lib/bson/symbol.rb, line 59 def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?) to_s.to_bson(buffer) end
Get the symbol as a BSON
key name encoded C symbol.
@example Get the symbol as a key name.
:test.to_bson_key
@return [ String
] The encoded symbol as a BSON
key.
@see bsonspec.org/#/specification
@since 2.0.0
# File lib/bson/symbol.rb, line 73 def to_bson_key(validating_keys = Config.validating_keys?) to_s.to_bson_key(validating_keys) end