2010-05-07 19:33:27 +00:00
|
|
|
# encoding: UTF-8
|
|
|
|
|
2010-04-05 18:09:06 +00:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
|
2010-09-20 19:07:30 +00:00
|
|
|
MINIMUM_BSON_EXT_VERSION = "1.0.9"
|
2010-05-24 15:43:28 +00:00
|
|
|
|
2010-04-05 18:09:06 +00:00
|
|
|
module BSON
|
2010-09-20 19:07:30 +00:00
|
|
|
VERSION = "1.0.9"
|
2010-04-05 18:09:06 +00:00
|
|
|
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
|
2010-05-28 18:01:51 +00:00
|
|
|
|
|
|
|
# Reads a single BSON document from an IO object.
|
2010-05-28 18:04:07 +00:00
|
|
|
# This method is used in the executable b2json, bundled with
|
2010-05-28 18:04:33 +00:00
|
|
|
# the bson gem, for reading a file of bson documents.
|
2010-05-28 18:01:51 +00:00
|
|
|
#
|
|
|
|
# @param [IO] io an io object containing a bson object.
|
|
|
|
#
|
|
|
|
# @return [ByteBuffer]
|
|
|
|
def self.read_bson_document(io)
|
|
|
|
bytebuf = BSON::ByteBuffer.new
|
|
|
|
sz = io.read(4).unpack("V")[0]
|
|
|
|
bytebuf.put_int(sz)
|
|
|
|
bytebuf.put_array(io.read(sz-4).unpack("C*"))
|
|
|
|
bytebuf.rewind
|
|
|
|
return BSON.deserialize(bytebuf)
|
|
|
|
end
|
2010-04-05 18:09:06 +00:00
|
|
|
end
|
|
|
|
|
2010-09-30 13:43:17 +00:00
|
|
|
if RUBY_PLATFORM =~ /java/
|
|
|
|
jar_dir = File.join(File.dirname(__FILE__), '..', 'ext', 'java', 'jar')
|
|
|
|
require File.join(jar_dir, 'mongo.jar')
|
|
|
|
require File.join(jar_dir, 'bson.jar')
|
|
|
|
require File.join(jar_dir, 'jbson.jar')
|
|
|
|
require 'bson/bson_java'
|
2010-04-05 18:09:06 +00:00
|
|
|
module BSON
|
2010-09-30 13:43:17 +00:00
|
|
|
BSON_CODER = BSON_JAVA
|
2010-04-05 18:09:06 +00:00
|
|
|
end
|
2010-09-30 13:43:17 +00:00
|
|
|
else
|
|
|
|
begin
|
|
|
|
# Need this for running test with and without c ext in Ruby 1.9.
|
|
|
|
raise LoadError if ENV['TEST_MODE'] && !ENV['C_EXT']
|
|
|
|
require 'bson_ext/cbson'
|
|
|
|
raise LoadError unless defined?(CBson::VERSION)
|
|
|
|
if CBson::VERSION < MINIMUM_BSON_EXT_VERSION
|
|
|
|
puts "Able to load bson_ext version #{CBson::VERSION}, but >= #{MINIMUM_BSON_EXT_VERSION} is required."
|
|
|
|
raise LoadError
|
|
|
|
end
|
|
|
|
require 'bson/bson_c'
|
|
|
|
module BSON
|
|
|
|
BSON_CODER = BSON_C
|
|
|
|
end
|
|
|
|
rescue LoadError
|
|
|
|
require 'bson/bson_ruby'
|
|
|
|
module BSON
|
|
|
|
BSON_CODER = BSON_RUBY
|
|
|
|
end
|
|
|
|
warn "\n**Notice: C extension not loaded. This is required for optimum MongoDB Ruby driver performance."
|
|
|
|
warn " You can install the extension as follows:\n gem install bson_ext\n"
|
|
|
|
warn " If you continue to receive this message after installing, make sure that the"
|
|
|
|
warn " bson_ext gem is in your load path and that the bson_ext and mongo gems are of the same version.\n"
|
2010-04-05 18:09:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
require 'bson/types/binary'
|
|
|
|
require 'bson/types/code'
|
|
|
|
require 'bson/types/dbref'
|
|
|
|
require 'bson/types/objectid'
|
2010-08-24 16:49:23 +00:00
|
|
|
require 'bson/types/object_id'
|
2010-04-05 18:09:06 +00:00
|
|
|
require 'bson/types/min_max_keys'
|
|
|
|
|
|
|
|
require 'base64'
|
|
|
|
require 'bson/ordered_hash'
|
|
|
|
require 'bson/byte_buffer'
|
|
|
|
require 'bson/bson_ruby'
|
|
|
|
require 'bson/exceptions'
|