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

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

Constants inherited from ByteBuffer

BINARY_ENCODING, NULL_BYTE, UTF8_ENCODING

Instance Attribute Summary (collapse)

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, #rewind, serialize_cstr, #size, #to_a, #to_s, to_utf8_binary, #unpack

Constructor Details

- (Binary) initialize(data = [], subtype = SUBTYPE_BYTES)

Create a buffer for storing binary data in MongoDB.

Parameters:

  • (Array, String) data (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.

  • (Fixnum) one

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

See Also:



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

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

Instance Attribute Details

- (Object) subtype

One of the SUBTYPE_* constants. Default is SUBTYPE_BYTES.



36
37
38
# File 'lib/bson/types/binary.rb', line 36

def subtype
  @subtype
end

Instance Method Details

- (Object) inspect



51
52
53
# File 'lib/bson/types/binary.rb', line 51

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