BSON serialize now takes a ByteBuffer.
This commit is contained in:
parent
01dc72c834
commit
1bbb9fb78f
|
@ -287,13 +287,18 @@ class BSON
|
||||||
buf.put(BINARY)
|
buf.put(BINARY)
|
||||||
self.class.serialize_cstr(buf, key)
|
self.class.serialize_cstr(buf, key)
|
||||||
|
|
||||||
bytes = if RUBY_VERSION >= '1.9'
|
bytes = case val
|
||||||
|
when ByteBuffer
|
||||||
|
val.to_a
|
||||||
|
else
|
||||||
|
if RUBY_VERSION >= '1.9'
|
||||||
val.bytes.to_a
|
val.bytes.to_a
|
||||||
else
|
else
|
||||||
a = []
|
a = []
|
||||||
val.each_byte { |byte| a << byte }
|
val.each_byte { |byte| a << byte }
|
||||||
a
|
a
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
num_bytes = bytes.length
|
num_bytes = bytes.length
|
||||||
buf.put_int(num_bytes + 4)
|
buf.put_int(num_bytes + 4)
|
||||||
|
@ -422,7 +427,7 @@ class BSON
|
||||||
NUMBER_INT
|
NUMBER_INT
|
||||||
when Numeric
|
when Numeric
|
||||||
NUMBER
|
NUMBER
|
||||||
when XGen::Mongo::Driver::Binary # must be before String
|
when XGen::Mongo::Driver::Binary, ByteBuffer # must be before String
|
||||||
BINARY
|
BINARY
|
||||||
when String
|
when String
|
||||||
# magic awful stuff - the DB requires that a where clause is sent as CODE
|
# magic awful stuff - the DB requires that a where clause is sent as CODE
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = 'mongo'
|
s.name = 'mongo'
|
||||||
s.version = '0.2.6'
|
s.version = '0.2.7'
|
||||||
s.platform = Gem::Platform::RUBY
|
s.platform = Gem::Platform::RUBY
|
||||||
s.summary = 'Simple pure-Ruby driver for the 10gen Mongo DB'
|
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.'
|
s.description = 'A pure-Ruby driver for the 10gen Mongo DB. For more information about Mongo, see http://www.mongodb.org.'
|
||||||
|
|
|
@ -125,6 +125,18 @@ class BSONTest < Test::Unit::TestCase
|
||||||
assert_equal 'binstring', doc2['bin']
|
assert_equal 'binstring', doc2['bin']
|
||||||
end
|
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
|
def test_undefined
|
||||||
doc = {'undef' => Undefined.new}
|
doc = {'undef' => Undefined.new}
|
||||||
@b.serialize(doc)
|
@b.serialize(doc)
|
||||||
|
|
Loading…
Reference in New Issue