From cc7cac680ba197763c4a495d63025802c5101952 Mon Sep 17 00:00:00 2001 From: Jim Menard Date: Wed, 21 Jan 2009 12:09:18 -0500 Subject: [PATCH] Make ByteBuffer work no matter what the string encoding scheme. --- lib/mongo/util/byte_buffer.rb | 24 ++++++++---------------- mongo-ruby-driver.gemspec | 2 +- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/lib/mongo/util/byte_buffer.rb b/lib/mongo/util/byte_buffer.rb index 2c83fb1..49898b0 100644 --- a/lib/mongo/util/byte_buffer.rb +++ b/lib/mongo/util/byte_buffer.rb @@ -66,14 +66,10 @@ class ByteBuffer @cursor += array.length end - 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 + def put_int(i, offset=nil) + a = [] + [i].pack(@int_pack_order).each_byte { |b| a << b } + put_array(a, offset) end def put_long(i, offset=nil) @@ -87,14 +83,10 @@ class ByteBuffer end end - 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 + def put_double(d, offset=nil) + a = [] + [d].pack(@double_pack_order).each_byte { |b| a << b } + put_array(a, offset) end # If +size+ == nil, returns one byte. Else returns array of bytes of length diff --git a/mongo-ruby-driver.gemspec b/mongo-ruby-driver.gemspec index 8577c06..44dc6ff 100644 --- a/mongo-ruby-driver.gemspec +++ b/mongo-ruby-driver.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'mongo' - s.version = '0.2.1' + s.version = '0.2.2' 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.'