Class: BSON::BSON_JAVA

Inherits:
Object
  • Object
show all
Defined in:
lib/bson/bson_java.rb

Class Method Summary collapse

Class Method Details

.deserialize(buf) ⇒ Object



13
14
15
16
17
18
# File 'lib/bson/bson_java.rb', line 13

def self.deserialize(buf)
  dec = Java::OrgBson::BSONDecoder.new
  callback = Java::OrgJbson::RubyBSONCallback.new(JRuby.runtime)
  dec.decode(buf.to_s.to_java_bytes, callback)
  callback.get
end

.max_bson_sizeObject



20
21
22
# File 'lib/bson/bson_java.rb', line 20

def self.max_bson_size
  Java::OrgJbson::RubyBSONEncoder.max_bson_size(self)
end

.serialize(obj, check_keys = false, move_id = false) ⇒ Object

TODO: Pool or cache instances of RubyBSONEncoder so that we don’t create a new one on each call to #serialize.

Raises:



7
8
9
10
11
# File 'lib/bson/bson_java.rb', line 7

def self.serialize(obj, check_keys=false, move_id=false)
  raise InvalidDocument, "BSON_JAVA.serialize takes a Hash" unless obj.is_a?(Hash)
  enc = Java::OrgJbson::RubyBSONEncoder.new(JRuby.runtime, check_keys, move_id)
  ByteBuffer.new(enc.encode(obj))
end

.update_max_bson_size(connection) ⇒ Object



24
25
26
# File 'lib/bson/bson_java.rb', line 24

def self.update_max_bson_size(connection)
  Java::OrgJbson::RubyBSONEncoder.update_max_bson_size(self, connection)
end