Skip to content

Commit e9de3e5

Browse files
committed
RUBY-139 add new sub-type 0. Will become default with the release of mongod 1.8
1 parent fd07b40 commit e9de3e5

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/bson/types/binary.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ module BSON
2626
# Use this class when storing binary data in documents.
2727
class Binary < ByteBuffer
2828

29-
SUBTYPE_BYTES = 0x02
30-
SUBTYPE_UUID = 0x03
31-
SUBTYPE_MD5 = 0x05
29+
SUBTYPE_SIMPLE = 0x00
30+
SUBTYPE_BYTES = 0x02
31+
SUBTYPE_UUID = 0x03
32+
SUBTYPE_MD5 = 0x05
3233
SUBTYPE_USER_DEFINED = 0x80
3334

3435
# One of the SUBTYPE_* constants. Default is SUBTYPE_BYTES.

test/mongo_bson/bson_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,18 @@ def test_binary_type
309309
assert_equal Binary::SUBTYPE_USER_DEFINED, bin2.subtype
310310
end
311311

312+
def test_binary_binary_subtype_0
313+
bin = Binary.new([1, 2, 3, 4, 5], Binary::SUBTYPE_SIMPLE)
314+
315+
doc = {'bin' => bin}
316+
bson = BSON::BSON_CODER.serialize(doc)
317+
doc2 = BSON::BSON_CODER.deserialize(bson)
318+
bin2 = doc2['bin']
319+
assert_kind_of Binary, bin2
320+
assert_equal [1, 2, 3, 4, 5], bin2.to_a
321+
assert_equal Binary::SUBTYPE_SIMPLE, bin2.subtype
322+
end
323+
312324
def test_binary_byte_buffer
313325
bb = Binary.new
314326
5.times { |i| bb.put(i + 1) }

0 commit comments

Comments
 (0)