diff --git a/ext/cbson/cbson.c b/ext/cbson/cbson.c index 065f23c..4c0c9ce 100644 --- a/ext/cbson/cbson.c +++ b/ext/cbson/cbson.c @@ -904,8 +904,9 @@ static VALUE objectid_generate(VALUE self) return oid; } -static void method_update_max_bson_size(VALUE self, VALUE connection) { +static VALUE method_update_max_bson_size(VALUE self, VALUE connection) { max_bson_size = FIX2INT(rb_funcall(connection, rb_intern("max_bson_size"), 0)); + return INT2FIX(max_bson_size); } static VALUE method_max_bson_size(VALUE self) { diff --git a/ext/java/jar/jbson.jar b/ext/java/jar/jbson.jar index 672589a..720fc27 100644 Binary files a/ext/java/jar/jbson.jar and b/ext/java/jar/jbson.jar differ diff --git a/ext/java/src/org/jbson/RubyBSONEncoder.java b/ext/java/src/org/jbson/RubyBSONEncoder.java index 9c4b06d..8dbd1b0 100644 --- a/ext/java/src/org/jbson/RubyBSONEncoder.java +++ b/ext/java/src/org/jbson/RubyBSONEncoder.java @@ -91,10 +91,11 @@ public class RubyBSONEncoder extends BSONEncoder { return _run.newFixnum(_max_bson_size); } - public static void update_max_bson_size(RubyObject obj, RubyObject conn) { + public static RubyFixnum update_max_bson_size(RubyObject obj, RubyObject conn) { Ruby _run = obj.getRuntime(); _max_bson_size = ((Long)JavaEmbedUtils.invokeMethod( _run, conn, "max_bson_size", new Object[] {}, Object.class)).intValue(); + return _run.newFixnum(_max_bson_size); } public RubyString encode( Object arg ) { diff --git a/lib/bson.rb b/lib/bson.rb index 556f568..b5b1910 100644 --- a/lib/bson.rb +++ b/lib/bson.rb @@ -6,11 +6,17 @@ MINIMUM_BSON_EXT_VERSION = "1.2.rc0" module BSON VERSION = "1.2.rc0" + + if defined? Mongo + DEFAULT_MAX_BSON_SIZE = Mongo::DEFAULT_MAX_BSON_SIZE + else + DEFAULT_MAX_BSON_SIZE = 4 * 1024 * 1024 + end + def self.serialize(obj, check_keys=false, move_id=false) BSON_CODER.serialize(obj, check_keys, move_id) end - def self.deserialize(buf=nil) BSON_CODER.deserialize(buf) end diff --git a/test/bson/bson_test.rb b/test/bson/bson_test.rb index c88c762..a7a8b75 100644 --- a/test/bson/bson_test.rb +++ b/test/bson/bson_test.rb @@ -78,6 +78,15 @@ class BSONTest < Test::Unit::TestCase assert BSON_CODER.max_bson_size >= BSON::DEFAULT_MAX_BSON_SIZE end + def test_update_max_bson_size + require 'ostruct' + mock_conn = OpenStruct.new + size = 7 * 1024 * 1024 + mock_conn.max_bson_size = size + assert_equal size, BSON_CODER.update_max_bson_size(mock_conn) + assert_equal size, BSON_CODER.max_bson_size + end + def test_round_trip doc = {'doc' => 123} @encoder.deserialize(@encoder.serialize(doc))