2010-09-30 13:43:17 +00:00
|
|
|
include Java
|
|
|
|
module BSON
|
|
|
|
class BSON_JAVA
|
|
|
|
|
2010-10-01 17:57:16 +00:00
|
|
|
# TODO: Pool or cache instances of RubyBSONEncoder so that
|
|
|
|
# we don't create a new one on each call to #serialize.
|
2010-09-30 13:43:17 +00:00
|
|
|
def self.serialize(obj, check_keys=false, move_id=false)
|
|
|
|
raise InvalidDocument, "BSON_JAVA.serialize takes a Hash" unless obj.is_a?(Hash)
|
2010-10-07 21:42:39 +00:00
|
|
|
enc = Java::OrgJbson::RubyBSONEncoder.new(JRuby.runtime, check_keys, move_id)
|
2010-09-30 13:43:17 +00:00
|
|
|
ByteBuffer.new(enc.encode(obj))
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.deserialize(buf)
|
2011-05-11 14:59:21 +00:00
|
|
|
dec = Java::OrgJbson::RubyBSONDecoder.new
|
2010-10-01 17:57:16 +00:00
|
|
|
callback = Java::OrgJbson::RubyBSONCallback.new(JRuby.runtime)
|
2010-09-30 13:43:17 +00:00
|
|
|
dec.decode(buf.to_s.to_java_bytes, callback)
|
|
|
|
callback.get
|
|
|
|
end
|
|
|
|
|
2010-12-29 23:06:31 +00:00
|
|
|
def self.max_bson_size
|
|
|
|
Java::OrgJbson::RubyBSONEncoder.max_bson_size(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.update_max_bson_size(connection)
|
|
|
|
Java::OrgJbson::RubyBSONEncoder.update_max_bson_size(self, connection)
|
|
|
|
end
|
2010-09-30 13:43:17 +00:00
|
|
|
end
|
|
|
|
end
|