Class: BSON::Binary

Inherits:
ByteBuffer show all
Defined in:
lib/bson/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_SIMPLE =
0x00
SUBTYPE_BYTES =
0x02
SUBTYPE_UUID =
0x03
SUBTYPE_MD5 =
0x05
SUBTYPE_USER_DEFINED =
0x80

Constants inherited from ByteBuffer

BSON::ByteBuffer::DOUBLE_PACK, BSON::ByteBuffer::INT32_PACK, BSON::ByteBuffer::INT64_PACK

Instance Attribute Summary collapse

Attributes inherited from ByteBuffer

#max_size, #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_binary, #put_double, #put_int, #put_long, #put_num, #rewind, #size, #to_a, #to_s, #unpack

Constructor Details

#initialize(data = [], subtype = SUBTYPE_SIMPLE) ⇒ Binary

Create a buffer for storing binary data in MongoDB.

Parameters:

  • data (Array, String) (defaults to: [])

    to story as BSON binary. If a string is given, the on Ruby 1.9 it will be forced to the binary encoding.

  • 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/bson/types/binary.rb', line 42

def initialize(data=[], subtype=SUBTYPE_SIMPLE)
  super(data)
  @subtype = subtype
end

Instance Attribute Details

#subtypeObject

One of the SUBTYPE_* constants. Default is SUBTYPE_BYTES.


32
33
34
# File 'lib/bson/types/binary.rb', line 32

def subtype
  @subtype
end

Instance Method Details

#inspectObject


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

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