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



15
16
17
18
19
20
# File 'lib/bson/bson_java.rb', line 15

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

.max_bson_sizeObject



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

def self.max_bson_size
  warn "BSON::BSON_CODER.max_bson_size is deprecated and will be removed in v2.0."
  Java::OrgJbson::RubyBSONEncoder.max_bson_size(self)
end

.serialize(obj, check_keys = false, move_id = false, max_bson_size = BSON::DEFAULT_MAX_BSON_SIZE) ⇒ Object

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

Raises:



9
10
11
12
13
# File 'lib/bson/bson_java.rb', line 9

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

.update_max_bson_size(connection) ⇒ Object



27
28
29
30
# File 'lib/bson/bson_java.rb', line 27

def self.update_max_bson_size(connection)
  warn "BSON::BSON_CODER.update_max_bson_size is deprecated and now a no-op. It will be removed in v2.0."
  Java::OrgJbson::RubyBSONEncoder.update_max_bson_size(self, connection)
end