Class: Moped::BSON::Binary
Constant Summary collapse
- SUBTYPE_MAP =
{ generic: "\x00", function: "\x01", old: "\x02", uuid: "\x03", md5: "\x05", user: "\x80" }
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #__bson_dump__(io, key) ⇒ Object
- #hash ⇒ Object
-
#initialize(type, data) ⇒ Binary
constructor
A new instance of Binary.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(type, data) ⇒ Binary
Returns a new instance of Binary.
16 17 18 19 |
# File 'lib/moped/bson/binary.rb', line 16 def initialize(type, data) @type = type @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
14 15 16 |
# File 'lib/moped/bson/binary.rb', line 14 def data @data end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
14 15 16 |
# File 'lib/moped/bson/binary.rb', line 14 def type @type end |
Class Method Details
.__bson_load__(io) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/moped/bson/binary.rb', line 22 def __bson_load__(io) length, = io.read(4).unpack(INT32_PACK) type = SUBTYPE_MAP.invert[io.read(1)] if type == :old length -= 4 io.read(4) end data = io.read length new(type, data) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
36 37 38 |
# File 'lib/moped/bson/binary.rb', line 36 def ==(other) BSON::Binary === other && data == other.data && type == other.type end |
#__bson_dump__(io, key) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/moped/bson/binary.rb', line 45 def __bson_dump__(io, key) io << Types::BINARY io << key io << NULL_BYTE if type == :old io << [data.bytesize + 4].pack(INT32_PACK) io << SUBTYPE_MAP[type] io << [data.bytesize].pack(INT32_PACK) io << data else io << [data.bytesize].pack(INT32_PACK) io << SUBTYPE_MAP[type] io << data end end |
#hash ⇒ Object
41 42 43 |
# File 'lib/moped/bson/binary.rb', line 41 def hash [data, type].hash end |
#inspect ⇒ Object
62 63 64 |
# File 'lib/moped/bson/binary.rb', line 62 def inspect "#<#{self.class.name} type=#{type.inspect} length=#{data.bytesize}>" end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/moped/bson/binary.rb', line 66 def to_s data.to_s end |