Class: Mongo::Binary

Inherits:
ByteBuffer show all
Defined in:
lib/mongo/types/binary.rb

Overview

An array of binary bytes with a MongoDB subtype. See the subtype constants for reference.

Use this class when storing binary data in documents.

Constant Summary collapse

SUBTYPE_BYTES =
0x02
SUBTYPE_UUID =
0x03
SUBTYPE_MD5 =
0x05
SUBTYPE_USER_DEFINED =
0x80

Constants inherited from ByteBuffer

ByteBuffer::INT_LOOKUP

Instance Attribute Summary collapse

Attributes inherited from ByteBuffer

#order

Instance Method Summary collapse

Methods inherited from ByteBuffer

#append!, #clear, #dump, #get, #get_double, #get_int, #get_long, #more?, #position, #position=, #prepend!, #put, #put_array, #put_double, #put_int, #put_long, #rewind, serialize_cstr, #size, #to_a, #to_s, to_utf8, #unpack

Constructor Details

#initialize(initial_data = [], subtype = SUBTYPE_BYTES) ⇒ Binary

Create a buffer for storing binary data in MongoDB.

Parameters:

  • initia_data (Array)
  • one (Fixnum)

    of four values specifying a BSON binary subtype. Possible values are SUBTYPE_BYTES, SUBTYPE_UUID, SUBTYPE_MD5, and SUBTYPE_USER_DEFINED.

See Also:



42
43
44
45
# File 'lib/mongo/types/binary.rb', line 42

def initialize(initial_data=[], subtype=SUBTYPE_BYTES)
  super(initial_data)
  @subtype = subtype
end

Instance Attribute Details

#subtypeObject

One of the SUBTYPE_* constants. Default is SUBTYPE_BYTES.



33
34
35
# File 'lib/mongo/types/binary.rb', line 33

def subtype
  @subtype
end

Instance Method Details

#inspectObject



47
48
49
# File 'lib/mongo/types/binary.rb', line 47

def inspect
  "<Mongo::Binary:#{object_id}>"
end