Object
Deserialize the binary data from BSON.
@param [ BSON ] bson The bson representing binary data.
@return [ Binary ] The decoded binary data.
@see bsonspec.org/#/specification
@since 2.0.0
# File lib/bson/binary.rb, line 126 def self.from_bson(bson) length = Int32.from_bson(bson) type = TYPES[bson.read(1)] length = Int32.from_bson(bson) if type == :old data = bson.read(length) new(data, type) end
Instantiate the new binary object.
@example Instantiate a binary.
BSON::Binary.new(data, :md5)
@param [ Object ] data The raw binary data. @param [ Symbol ] type The binary type.
@since 2.0.0
# File lib/bson/binary.rb, line 93 def initialize(data = "", type = :generic) validate_type!(type) @data = data @type = type end
Determine if this binary object is equal to another object.
@example Check the binary equality.
binary == other
@param [ Object ] other The object to compare against.
@return [ true, false ] If the objects are equal.
@since 2.0.0
# File lib/bson/binary.rb, line 67 def ==(other) return false unless other.is_a?(Binary) type == other.type && data == other.data end
Encode the binary type
@example Encode the binary.
binary.to_bson
@return [ String ] The encoded binary.
@see bsonspec.org/#/specification
@since 2.0.0
# File lib/bson/binary.rb, line 109 def to_bson(encoded = ''.force_encoding(BINARY)) encode_binary_data_with_placeholder(encoded) do |encoded| encoded << SUBTYPES.fetch(type) encoded << data.bytesize.to_bson if type == :old encoded << data end end
Generated with the Darkfish Rdoc Generator 2.