Fixed byte buffer double encoding problem. Made byte buffer work under Ruby 1.9.
This commit is contained in:
parent
d79551eaa8
commit
bce01bbaa6
@ -49,8 +49,14 @@ class ByteBuffer
|
||||
@cursor += array.length
|
||||
end
|
||||
|
||||
def put_int(i, offset=nil)
|
||||
put_array([i].pack(@int_pack_order).split(//).collect{|c| c[0]}, offset)
|
||||
if RUBY_VERSION >= '1.9'
|
||||
def put_int(i, offset=nil)
|
||||
put_array([i].pack(@int_pack_order).split(//).collect{|c| c.bytes.first}, offset)
|
||||
end
|
||||
else
|
||||
def put_int(i, offset=nil)
|
||||
put_array([i].pack(@int_pack_order).split(//).collect{|c| c[0]}, offset)
|
||||
end
|
||||
end
|
||||
|
||||
def put_long(i, offset=nil)
|
||||
@ -64,8 +70,14 @@ class ByteBuffer
|
||||
end
|
||||
end
|
||||
|
||||
def put_double(d, offset=nil)
|
||||
put_array([d].pack(@double_pack_order).split(//), offset)
|
||||
if RUBY_VERSION >= '1.9'
|
||||
def put_double(d, offset=nil)
|
||||
put_array([d].pack(@double_pack_order).split(//).collect{|c| c.bytes.first}, offset)
|
||||
end
|
||||
else
|
||||
def put_double(d, offset=nil)
|
||||
put_array([d].pack(@double_pack_order).split(//).collect{|c| c[0]}, offset)
|
||||
end
|
||||
end
|
||||
|
||||
# If +size+ == 1, returns one byte. Else returns array of bytes of length
|
||||
|
17
tests/test_bson.rb
Normal file
17
tests/test_bson.rb
Normal file
@ -0,0 +1,17 @@
|
||||
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
||||
require 'mongo'
|
||||
require 'test/unit'
|
||||
|
||||
# NOTE: assumes Mongo is running
|
||||
class BSONTest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
@b = BSON.new
|
||||
end
|
||||
|
||||
def test_object_encoding
|
||||
doc = {'doc' => {'age' => 41.2, 'name' => 'Spongebob'}}
|
||||
@b.serialize(doc)
|
||||
assert_equal doc, @b.deserialize
|
||||
end
|
||||
end
|
@ -32,6 +32,12 @@ class ByteBufferTest < Test::Unit::TestCase
|
||||
assert_equal 1027, @buf.get_long
|
||||
end
|
||||
|
||||
def test_get_double
|
||||
@buf.put_double 41.2
|
||||
@buf.rewind
|
||||
assert_equal 41.2, @buf.get_double
|
||||
end
|
||||
|
||||
def test_rewrite
|
||||
@buf.put_int(0)
|
||||
@buf.rewind
|
||||
|
Loading…
Reference in New Issue
Block a user