BSON serialize now takes a ByteBuffer.

This commit is contained in:
Jim Menard 2009-01-26 13:52:11 -05:00
parent 01dc72c834
commit 1bbb9fb78f
3 changed files with 24 additions and 7 deletions

View File

@ -287,12 +287,17 @@ class BSON
buf.put(BINARY)
self.class.serialize_cstr(buf, key)
bytes = if RUBY_VERSION >= '1.9'
val.bytes.to_a
bytes = case val
when ByteBuffer
val.to_a
else
a = []
val.each_byte { |byte| a << byte }
a
if RUBY_VERSION >= '1.9'
val.bytes.to_a
else
a = []
val.each_byte { |byte| a << byte }
a
end
end
num_bytes = bytes.length
@ -422,7 +427,7 @@ class BSON
NUMBER_INT
when Numeric
NUMBER
when XGen::Mongo::Driver::Binary # must be before String
when XGen::Mongo::Driver::Binary, ByteBuffer # must be before String
BINARY
when String
# magic awful stuff - the DB requires that a where clause is sent as CODE

View File

@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'mongo'
s.version = '0.2.6'
s.version = '0.2.7'
s.platform = Gem::Platform::RUBY
s.summary = 'Simple pure-Ruby driver for the 10gen Mongo DB'
s.description = 'A pure-Ruby driver for the 10gen Mongo DB. For more information about Mongo, see http://www.mongodb.org.'

View File

@ -125,6 +125,18 @@ class BSONTest < Test::Unit::TestCase
assert_equal 'binstring', doc2['bin']
end
# def test_binary_byte_buffer
# bb = ByteBuffer.new
# 10.times { |i| bb.put(i) }
# doc = {'bin' => bb}
# @b.serialize(doc)
# doc2 = @b.deserialize
# doc2_bytes = []
# doc2['bin'].each_byte { |b| doc2_bytes << b }
# assert_equal bb.to_a, doc2_bytes
# end
def test_undefined
doc = {'undef' => Undefined.new}
@b.serialize(doc)