RUBY-187 ByteBuffer should take another ByteBuffer as initial data
This commit is contained in:
parent
0c8d27c0b2
commit
cd03fafb27
|
@ -23,15 +23,19 @@ module BSON
|
||||||
attr_reader :order
|
attr_reader :order
|
||||||
|
|
||||||
def initialize(initial_data="")
|
def initialize(initial_data="")
|
||||||
if initial_data.is_a?(String)
|
@str = case initial_data
|
||||||
if initial_data.respond_to?(:force_encoding)
|
when String then
|
||||||
@str = initial_data.force_encoding('binary')
|
if initial_data.respond_to?(:force_encoding)
|
||||||
|
initial_data.force_encoding('binary')
|
||||||
|
else
|
||||||
|
initial_data
|
||||||
|
end
|
||||||
|
when BSON::ByteBuffer then
|
||||||
|
initial_data.to_a.pac('C*')
|
||||||
else
|
else
|
||||||
@str = initial_data
|
initial_data.pack('C*')
|
||||||
end
|
|
||||||
else
|
|
||||||
@str = initial_data.pack('C*')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@cursor = @str.length
|
@cursor = @str.length
|
||||||
@order = :little_endian
|
@order = :little_endian
|
||||||
@int_pack_order = 'V'
|
@int_pack_order = 'V'
|
||||||
|
|
|
@ -74,6 +74,11 @@ class BSONTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_round_trip
|
||||||
|
doc = {'doc' => 123}
|
||||||
|
@encoder.deserialize(@encoder.serialize(doc))
|
||||||
|
end
|
||||||
|
|
||||||
# In 1.8 we test that other string encodings raise an exception.
|
# In 1.8 we test that other string encodings raise an exception.
|
||||||
# In 1.9 we test that they get auto-converted.
|
# In 1.9 we test that they get auto-converted.
|
||||||
if RUBY_VERSION < '1.9'
|
if RUBY_VERSION < '1.9'
|
||||||
|
|
Loading…
Reference in New Issue