2008-12-17 16:49:06 +00:00
|
|
|
# --
|
2009-01-06 15:51:01 +00:00
|
|
|
# Copyright (C) 2008-2009 10gen Inc.
|
2008-12-17 16:43:08 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU Affero General Public License, version 3, as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
|
|
|
|
# for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-12-17 16:49:06 +00:00
|
|
|
# ++
|
2008-12-17 16:43:08 +00:00
|
|
|
|
2009-01-10 00:58:53 +00:00
|
|
|
require 'base64'
|
2008-11-22 01:00:51 +00:00
|
|
|
require 'mongo/util/byte_buffer'
|
2008-12-08 20:27:20 +00:00
|
|
|
require 'mongo/util/ordered_hash'
|
2009-01-13 15:23:20 +00:00
|
|
|
require 'mongo/types/binary'
|
|
|
|
require 'mongo/types/dbref'
|
|
|
|
require 'mongo/types/objectid'
|
|
|
|
require 'mongo/types/regexp_of_holding'
|
|
|
|
require 'mongo/types/undefined'
|
2008-11-22 01:00:51 +00:00
|
|
|
|
2008-12-17 16:43:08 +00:00
|
|
|
# A BSON seralizer/deserializer.
|
2008-11-22 01:00:51 +00:00
|
|
|
class BSON
|
|
|
|
|
2008-12-16 11:57:13 +00:00
|
|
|
MINKEY = -1
|
|
|
|
EOO = 0
|
|
|
|
NUMBER = 1
|
|
|
|
STRING = 2
|
|
|
|
OBJECT = 3
|
2008-11-22 01:00:51 +00:00
|
|
|
ARRAY = 4
|
|
|
|
BINARY = 5
|
|
|
|
UNDEFINED = 6
|
2008-12-16 11:57:13 +00:00
|
|
|
OID = 7
|
|
|
|
BOOLEAN = 8
|
|
|
|
DATE = 9
|
|
|
|
NULL = 10
|
2008-11-22 01:00:51 +00:00
|
|
|
REGEX = 11
|
|
|
|
REF = 12
|
|
|
|
CODE = 13
|
|
|
|
SYMBOL = 14
|
|
|
|
CODE_W_SCOPE = 15
|
|
|
|
NUMBER_INT = 16
|
2008-12-16 11:57:13 +00:00
|
|
|
MAXKEY = 127
|
2008-11-22 01:00:51 +00:00
|
|
|
|
2009-01-13 17:53:55 +00:00
|
|
|
if RUBY_VERSION >= '1.9'
|
|
|
|
def self.to_utf8(str)
|
|
|
|
str.encode("utf-8")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
def self.to_utf8(str)
|
|
|
|
str # TODO punt for now
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-11-22 01:00:51 +00:00
|
|
|
def self.serialize_cstr(buf, val)
|
2009-01-13 17:53:55 +00:00
|
|
|
buf.put_array(to_utf8(val.to_s).unpack("C*") + [0])
|
2008-11-22 01:00:51 +00:00
|
|
|
end
|
|
|
|
|
2009-01-09 20:22:10 +00:00
|
|
|
def initialize(db=nil)
|
|
|
|
# db is only needed during deserialization when the data contains a DBRef
|
|
|
|
@db = db
|
2008-11-22 01:00:51 +00:00
|
|
|
@buf = ByteBuffer.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_a
|
|
|
|
@buf.to_a
|
|
|
|
end
|
|
|
|
|
|
|
|
def serialize(obj)
|
|
|
|
raise "Document is null" unless obj
|
|
|
|
|
|
|
|
@buf.rewind
|
|
|
|
# put in a placeholder for the total size
|
|
|
|
@buf.put_int(0)
|
|
|
|
|
|
|
|
obj.each {|k, v|
|
|
|
|
type = bson_type(v, k)
|
|
|
|
case type
|
2009-01-14 14:23:19 +00:00
|
|
|
when STRING, CODE, SYMBOL
|
2008-11-22 01:00:51 +00:00
|
|
|
serialize_string_element(@buf, k, v, type)
|
|
|
|
when NUMBER, NUMBER_INT
|
|
|
|
serialize_number_element(@buf, k, v, type)
|
|
|
|
when OBJECT
|
|
|
|
serialize_object_element(@buf, k, v)
|
|
|
|
when OID
|
|
|
|
serialize_oid_element(@buf, k, v)
|
2008-12-08 20:27:20 +00:00
|
|
|
when ARRAY
|
|
|
|
serialize_array_element(@buf, k, v)
|
2008-12-08 20:57:20 +00:00
|
|
|
when REGEX
|
|
|
|
serialize_regex_element(@buf, k, v)
|
2008-11-22 01:00:51 +00:00
|
|
|
when BOOLEAN
|
|
|
|
serialize_boolean_element(@buf, k, v)
|
|
|
|
when DATE
|
|
|
|
serialize_date_element(@buf, k, v)
|
|
|
|
when NULL
|
|
|
|
serialize_null_element(@buf, k)
|
2009-01-08 19:43:30 +00:00
|
|
|
when REF
|
|
|
|
serialize_dbref_element(@buf, k, v)
|
2009-01-10 00:58:53 +00:00
|
|
|
when BINARY
|
|
|
|
serialize_binary_element(@buf, k, v)
|
2009-01-12 17:08:02 +00:00
|
|
|
when UNDEFINED
|
|
|
|
serialize_undefined_element(@buf, k)
|
|
|
|
when CODE_W_SCOPE
|
2009-01-07 22:13:21 +00:00
|
|
|
# TODO
|
2008-12-16 11:57:13 +00:00
|
|
|
raise "unimplemented type #{type}"
|
2008-11-22 01:00:51 +00:00
|
|
|
else
|
2008-12-16 11:57:13 +00:00
|
|
|
raise "unhandled type #{type}"
|
2008-11-22 01:00:51 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
serialize_eoo_element(@buf)
|
|
|
|
@buf.put_int(@buf.size, 0)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2009-01-09 20:22:10 +00:00
|
|
|
def deserialize(buf=nil, parent=nil)
|
2008-12-16 12:07:29 +00:00
|
|
|
# If buf is nil, use @buf, assumed to contain already-serialized BSON.
|
|
|
|
# This is only true during testing.
|
|
|
|
@buf = ByteBuffer.new(buf.to_a) if buf
|
2008-11-22 01:00:51 +00:00
|
|
|
@buf.rewind
|
|
|
|
@buf.get_int # eat message size
|
2009-01-09 19:26:30 +00:00
|
|
|
doc = OrderedHash.new
|
2008-11-22 01:00:51 +00:00
|
|
|
while @buf.more?
|
|
|
|
type = @buf.get
|
|
|
|
case type
|
2008-12-16 12:23:22 +00:00
|
|
|
when STRING, CODE
|
2009-01-09 16:56:30 +00:00
|
|
|
key = deserialize_cstr(@buf)
|
2008-11-22 01:00:51 +00:00
|
|
|
doc[key] = deserialize_string_data(@buf)
|
2009-01-14 14:23:19 +00:00
|
|
|
when SYMBOL
|
|
|
|
key = deserialize_cstr(@buf)
|
|
|
|
doc[key] = deserialize_string_data(@buf).intern
|
2008-11-22 01:00:51 +00:00
|
|
|
when NUMBER
|
2009-01-09 16:56:30 +00:00
|
|
|
key = deserialize_cstr(@buf)
|
2008-11-22 01:00:51 +00:00
|
|
|
doc[key] = deserialize_number_data(@buf)
|
|
|
|
when NUMBER_INT
|
2009-01-09 16:56:30 +00:00
|
|
|
key = deserialize_cstr(@buf)
|
2008-11-22 01:00:51 +00:00
|
|
|
doc[key] = deserialize_number_int_data(@buf)
|
|
|
|
when OID
|
2009-01-09 16:56:30 +00:00
|
|
|
key = deserialize_cstr(@buf)
|
2008-11-22 01:00:51 +00:00
|
|
|
doc[key] = deserialize_oid_data(@buf)
|
2008-12-08 20:27:20 +00:00
|
|
|
when ARRAY
|
2009-01-09 16:56:30 +00:00
|
|
|
key = deserialize_cstr(@buf)
|
2009-01-09 20:22:10 +00:00
|
|
|
doc[key] = deserialize_array_data(@buf, doc)
|
2008-12-08 20:57:20 +00:00
|
|
|
when REGEX
|
2009-01-09 16:56:30 +00:00
|
|
|
key = deserialize_cstr(@buf)
|
2008-12-08 20:57:20 +00:00
|
|
|
doc[key] = deserialize_regex_data(@buf)
|
2008-11-22 01:00:51 +00:00
|
|
|
when OBJECT
|
2009-01-09 16:56:30 +00:00
|
|
|
key = deserialize_cstr(@buf)
|
2009-01-09 20:22:10 +00:00
|
|
|
doc[key] = deserialize_object_data(@buf, doc)
|
2008-11-22 01:00:51 +00:00
|
|
|
when BOOLEAN
|
2009-01-09 16:56:30 +00:00
|
|
|
key = deserialize_cstr(@buf)
|
2008-11-22 01:00:51 +00:00
|
|
|
doc[key] = deserialize_boolean_data(@buf)
|
|
|
|
when DATE
|
2009-01-09 16:56:30 +00:00
|
|
|
key = deserialize_cstr(@buf)
|
2008-11-22 01:00:51 +00:00
|
|
|
doc[key] = deserialize_date_data(@buf)
|
2009-01-12 17:08:02 +00:00
|
|
|
when NULL
|
2009-01-09 16:56:30 +00:00
|
|
|
key = deserialize_cstr(@buf)
|
2008-11-22 01:00:51 +00:00
|
|
|
doc[key] = nil
|
2009-01-12 17:08:02 +00:00
|
|
|
when UNDEFINED
|
|
|
|
key = deserialize_cstr(@buf)
|
|
|
|
doc[key] = XGen::Mongo::Driver::Undefined.new
|
2009-01-08 19:43:30 +00:00
|
|
|
when REF
|
2009-01-09 16:56:30 +00:00
|
|
|
key = deserialize_cstr(@buf)
|
2009-01-09 20:22:10 +00:00
|
|
|
doc[key] = deserialize_dbref_data(@buf, key, parent)
|
2009-01-10 00:58:53 +00:00
|
|
|
when BINARY
|
|
|
|
key = deserialize_cstr(@buf)
|
2009-01-12 16:13:49 +00:00
|
|
|
doc[key] = deserialize_binary_data(@buf)
|
2009-01-10 00:58:53 +00:00
|
|
|
when CODE_W_SCOPE
|
2009-01-07 22:13:21 +00:00
|
|
|
# TODO
|
|
|
|
raise "unimplemented type #{type}"
|
2008-11-22 01:00:51 +00:00
|
|
|
when EOO
|
|
|
|
break
|
|
|
|
else
|
|
|
|
raise "Unknown type #{type}, key = #{key}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@buf.rewind
|
|
|
|
doc
|
|
|
|
end
|
|
|
|
|
2009-01-13 17:53:55 +00:00
|
|
|
# For debugging.
|
2008-11-22 01:00:51 +00:00
|
|
|
def hex_dump
|
|
|
|
str = ''
|
|
|
|
@buf.to_a.each_with_index { |b,i|
|
|
|
|
if (i % 8) == 0
|
|
|
|
str << "\n" if i > 0
|
|
|
|
str << '%4d: ' % i
|
|
|
|
else
|
|
|
|
str << ' '
|
|
|
|
end
|
|
|
|
str << '%02X' % b
|
|
|
|
}
|
|
|
|
str
|
|
|
|
end
|
|
|
|
|
|
|
|
def deserialize_date_data(buf)
|
2009-01-07 20:56:40 +00:00
|
|
|
millisecs = buf.get_long()
|
|
|
|
Time.at(millisecs.to_f / 1000.0) # at() takes fractional seconds
|
2008-11-22 01:00:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def deserialize_boolean_data(buf)
|
|
|
|
buf.get == 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def deserialize_number_data(buf)
|
|
|
|
buf.get_double
|
|
|
|
end
|
|
|
|
|
|
|
|
def deserialize_number_int_data(buf)
|
|
|
|
buf.get_int
|
|
|
|
end
|
|
|
|
|
2009-01-09 20:22:10 +00:00
|
|
|
def deserialize_object_data(buf, parent)
|
2008-11-22 01:00:51 +00:00
|
|
|
size = buf.get_int
|
|
|
|
buf.position -= 4
|
2009-01-09 20:22:10 +00:00
|
|
|
BSON.new(@db).deserialize(buf.get(size), parent)
|
2008-11-22 01:00:51 +00:00
|
|
|
end
|
|
|
|
|
2009-01-09 20:22:10 +00:00
|
|
|
def deserialize_array_data(buf, parent)
|
|
|
|
h = deserialize_object_data(buf, parent)
|
2008-12-08 20:27:20 +00:00
|
|
|
a = []
|
|
|
|
h.each { |k, v| a[k.to_i] = v }
|
|
|
|
a
|
|
|
|
end
|
|
|
|
|
2008-12-08 20:57:20 +00:00
|
|
|
def deserialize_regex_data(buf)
|
2009-01-09 16:56:30 +00:00
|
|
|
str = deserialize_cstr(buf)
|
|
|
|
options_str = deserialize_cstr(buf)
|
2008-12-08 20:57:20 +00:00
|
|
|
options = 0
|
|
|
|
options |= Regexp::IGNORECASE if options_str.include?('i')
|
|
|
|
options |= Regexp::MULTILINE if options_str.include?('m')
|
|
|
|
options |= Regexp::EXTENDED if options_str.include?('x')
|
2009-01-13 14:12:13 +00:00
|
|
|
options_str.gsub!(/[imx]/, '') # Now remove the three we understand
|
|
|
|
XGen::Mongo::Driver::RegexpOfHolding.new(str, options, options_str)
|
2008-12-08 20:57:20 +00:00
|
|
|
end
|
|
|
|
|
2008-11-22 01:00:51 +00:00
|
|
|
def deserialize_string_data(buf)
|
|
|
|
len = buf.get_int
|
|
|
|
bytes = buf.get(len)
|
2009-01-13 17:53:55 +00:00
|
|
|
str = bytes[0..-2].pack("C*")
|
|
|
|
if RUBY_VERSION >= '1.9'
|
|
|
|
str.force_encoding("utf-8")
|
|
|
|
end
|
|
|
|
str
|
2008-11-22 01:00:51 +00:00
|
|
|
end
|
|
|
|
|
2008-12-04 13:37:42 +00:00
|
|
|
def deserialize_oid_data(buf)
|
2008-12-09 18:48:38 +00:00
|
|
|
XGen::Mongo::Driver::ObjectID.new(buf.get(12))
|
2008-11-22 01:00:51 +00:00
|
|
|
end
|
|
|
|
|
2009-01-09 20:22:10 +00:00
|
|
|
def deserialize_dbref_data(buf, key, parent)
|
2009-01-09 16:56:30 +00:00
|
|
|
ns = deserialize_cstr(buf)
|
2009-01-08 19:43:30 +00:00
|
|
|
oid = deserialize_oid_data(buf)
|
2009-01-09 20:22:10 +00:00
|
|
|
XGen::Mongo::Driver::DBRef.new(parent, key, @db, ns, oid)
|
2009-01-08 19:43:30 +00:00
|
|
|
end
|
|
|
|
|
2009-01-12 16:13:49 +00:00
|
|
|
def deserialize_binary_data(buf)
|
2009-01-10 21:40:24 +00:00
|
|
|
len = buf.get_int
|
|
|
|
bytes = buf.get(len)
|
|
|
|
str = ''
|
|
|
|
bytes.each { |c| str << c.chr }
|
2009-01-12 16:11:58 +00:00
|
|
|
str.to_mongo_binary
|
2009-01-10 00:58:53 +00:00
|
|
|
end
|
|
|
|
|
2008-11-22 01:00:51 +00:00
|
|
|
def serialize_eoo_element(buf)
|
|
|
|
buf.put(EOO)
|
|
|
|
end
|
|
|
|
|
|
|
|
def serialize_null_element(buf, key)
|
|
|
|
buf.put(NULL)
|
|
|
|
self.class.serialize_cstr(buf, key)
|
|
|
|
end
|
|
|
|
|
2009-01-08 19:43:30 +00:00
|
|
|
def serialize_dbref_element(buf, key, val)
|
2009-01-09 16:56:30 +00:00
|
|
|
buf.put(REF)
|
|
|
|
self.class.serialize_cstr(buf, key)
|
|
|
|
self.class.serialize_cstr(buf, val.namespace)
|
2009-01-08 19:43:30 +00:00
|
|
|
buf.put_array(val.object_id.to_a)
|
|
|
|
end
|
|
|
|
|
2009-01-10 00:58:53 +00:00
|
|
|
def serialize_binary_element(buf, key, val)
|
|
|
|
buf.put(BINARY)
|
|
|
|
self.class.serialize_cstr(buf, key)
|
2009-01-12 15:48:04 +00:00
|
|
|
buf.put_int(val.length)
|
2009-01-10 21:40:24 +00:00
|
|
|
bytes = if RUBY_VERSION >= '1.9'
|
|
|
|
val.bytes.to_a
|
|
|
|
else
|
|
|
|
a = []
|
|
|
|
val.each_byte { |byte| a << byte }
|
|
|
|
a
|
|
|
|
end
|
|
|
|
buf.put_array(bytes)
|
2009-01-10 00:58:53 +00:00
|
|
|
end
|
|
|
|
|
2009-01-12 17:08:02 +00:00
|
|
|
def serialize_undefined_element(buf, key)
|
|
|
|
buf.put(UNDEFINED)
|
|
|
|
self.class.serialize_cstr(buf, key)
|
|
|
|
end
|
|
|
|
|
2008-11-22 01:00:51 +00:00
|
|
|
def serialize_boolean_element(buf, key, val)
|
|
|
|
buf.put(BOOLEAN)
|
|
|
|
self.class.serialize_cstr(buf, key)
|
|
|
|
buf.put(val ? 1 : 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
def serialize_date_element(buf, key, val)
|
|
|
|
buf.put(DATE)
|
|
|
|
self.class.serialize_cstr(buf, key)
|
2009-01-07 20:56:40 +00:00
|
|
|
millisecs = (val.to_f * 1000).to_i
|
|
|
|
buf.put_long(millisecs)
|
2008-11-22 01:00:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def serialize_number_element(buf, key, val, type)
|
|
|
|
buf.put(type)
|
|
|
|
self.class.serialize_cstr(buf, key)
|
|
|
|
if type == NUMBER
|
|
|
|
buf.put_double(val)
|
|
|
|
else
|
|
|
|
buf.put_int(val)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-12-08 20:27:20 +00:00
|
|
|
def serialize_object_element(buf, key, val, opcode=OBJECT)
|
|
|
|
buf.put(opcode)
|
2008-11-22 01:00:51 +00:00
|
|
|
self.class.serialize_cstr(buf, key)
|
2008-12-02 01:01:13 +00:00
|
|
|
buf.put_array(BSON.new.serialize(val).to_a)
|
2008-11-22 01:00:51 +00:00
|
|
|
end
|
|
|
|
|
2008-12-08 20:27:20 +00:00
|
|
|
def serialize_array_element(buf, key, val)
|
|
|
|
# Turn array into hash with integer indices as keys
|
|
|
|
h = OrderedHash.new
|
|
|
|
i = 0
|
|
|
|
val.each { |v| h[i] = v; i += 1 }
|
|
|
|
serialize_object_element(buf, key, h, ARRAY)
|
|
|
|
end
|
|
|
|
|
2008-12-08 20:57:20 +00:00
|
|
|
def serialize_regex_element(buf, key, val)
|
|
|
|
buf.put(REGEX)
|
|
|
|
self.class.serialize_cstr(buf, key)
|
|
|
|
|
|
|
|
str = val.to_s.sub(/.*?:/, '')[0..-2] # Turn "(?xxx:yyy)" into "yyy"
|
|
|
|
self.class.serialize_cstr(buf, str)
|
|
|
|
|
|
|
|
options = val.options
|
|
|
|
options_str = ''
|
|
|
|
options_str << 'i' if ((options & Regexp::IGNORECASE) != 0)
|
|
|
|
options_str << 'm' if ((options & Regexp::MULTILINE) != 0)
|
|
|
|
options_str << 'x' if ((options & Regexp::EXTENDED) != 0)
|
2009-01-13 14:12:13 +00:00
|
|
|
options_str << val.extra_options_str if val.respond_to?(:extra_options_str)
|
|
|
|
# Must store option chars in alphabetical order
|
|
|
|
self.class.serialize_cstr(buf, options_str.split(//).sort.uniq.join)
|
2008-12-08 20:57:20 +00:00
|
|
|
end
|
|
|
|
|
2008-11-22 01:00:51 +00:00
|
|
|
def serialize_oid_element(buf, key, val)
|
|
|
|
buf.put(OID)
|
|
|
|
self.class.serialize_cstr(buf, key)
|
2008-12-08 16:38:42 +00:00
|
|
|
|
2008-12-09 18:48:38 +00:00
|
|
|
buf.put_array(val.to_a)
|
2008-11-22 01:00:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def serialize_string_element(buf, key, val, type)
|
|
|
|
buf.put(type)
|
|
|
|
self.class.serialize_cstr(buf, key)
|
|
|
|
|
|
|
|
# Make a hole for the length
|
|
|
|
len_pos = buf.position
|
|
|
|
buf.put_int(0)
|
|
|
|
|
|
|
|
# Save the string
|
|
|
|
start_pos = buf.position
|
|
|
|
self.class.serialize_cstr(buf, val)
|
|
|
|
end_pos = buf.position
|
|
|
|
|
|
|
|
# Put the string size in front
|
2008-12-02 15:25:36 +00:00
|
|
|
buf.put_int(end_pos - start_pos, len_pos)
|
2008-11-22 01:00:51 +00:00
|
|
|
|
|
|
|
# Go back to where we were
|
|
|
|
buf.position = end_pos
|
|
|
|
end
|
|
|
|
|
2009-01-09 16:56:30 +00:00
|
|
|
def deserialize_cstr(buf)
|
2008-11-22 01:00:51 +00:00
|
|
|
chars = ""
|
|
|
|
while 1
|
|
|
|
b = buf.get
|
|
|
|
break if b == 0
|
|
|
|
chars << b.chr
|
|
|
|
end
|
2009-01-13 17:53:55 +00:00
|
|
|
if RUBY_VERSION >= '1.9'
|
|
|
|
chars.force_encoding("utf-8") # Mongo stores UTF-8
|
|
|
|
end
|
2008-11-22 01:00:51 +00:00
|
|
|
chars
|
|
|
|
end
|
|
|
|
|
|
|
|
def bson_type(o, key)
|
|
|
|
case o
|
|
|
|
when nil
|
|
|
|
NULL
|
|
|
|
when Integer
|
|
|
|
NUMBER_INT
|
|
|
|
when Numeric
|
|
|
|
NUMBER
|
2009-01-12 15:44:57 +00:00
|
|
|
when XGen::Mongo::Driver::Binary # must be before String
|
|
|
|
BINARY
|
2008-11-22 01:00:51 +00:00
|
|
|
when String
|
|
|
|
# magic awful stuff - the DB requires that a where clause is sent as CODE
|
|
|
|
key == "$where" ? CODE : STRING
|
|
|
|
when Array
|
|
|
|
ARRAY
|
2008-12-08 20:57:20 +00:00
|
|
|
when Regexp
|
|
|
|
REGEX
|
2008-12-02 01:01:13 +00:00
|
|
|
when XGen::Mongo::Driver::ObjectID
|
2008-11-22 01:00:51 +00:00
|
|
|
OID
|
2009-01-08 19:43:30 +00:00
|
|
|
when XGen::Mongo::Driver::DBRef
|
|
|
|
REF
|
2008-11-22 01:00:51 +00:00
|
|
|
when true, false
|
2008-12-16 12:33:39 +00:00
|
|
|
BOOLEAN
|
2008-11-22 01:00:51 +00:00
|
|
|
when Time
|
|
|
|
DATE
|
|
|
|
when Hash
|
|
|
|
OBJECT
|
2009-01-09 23:20:53 +00:00
|
|
|
when Symbol
|
|
|
|
SYMBOL
|
2009-01-12 17:08:02 +00:00
|
|
|
when XGen::Mongo::Driver::Undefined
|
|
|
|
UNDEFINED
|
2008-11-22 01:00:51 +00:00
|
|
|
else
|
|
|
|
raise "Unknown type of object: #{o.class.name}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|