include XGen::Mongo::Driver

This commit is contained in:
Jim Menard 2009-02-02 10:14:06 -05:00
parent 28daeb6600
commit d701fd7133
1 changed files with 13 additions and 11 deletions

View File

@ -26,6 +26,8 @@ require 'mongo/types/undefined'
# A BSON seralizer/deserializer. # A BSON seralizer/deserializer.
class BSON class BSON
include XGen::Mongo::Driver
MINKEY = -1 MINKEY = -1
EOO = 0 EOO = 0
NUMBER = 1 NUMBER = 1
@ -167,7 +169,7 @@ class BSON
doc[key] = nil doc[key] = nil
when UNDEFINED when UNDEFINED
key = deserialize_cstr(@buf) key = deserialize_cstr(@buf)
doc[key] = XGen::Mongo::Driver::Undefined.new doc[key] = Undefined.new
when REF when REF
key = deserialize_cstr(@buf) key = deserialize_cstr(@buf)
doc[key] = deserialize_dbref_data(@buf, key, parent) doc[key] = deserialize_dbref_data(@buf, key, parent)
@ -240,7 +242,7 @@ class BSON
options |= Regexp::MULTILINE if options_str.include?('m') options |= Regexp::MULTILINE if options_str.include?('m')
options |= Regexp::EXTENDED if options_str.include?('x') options |= Regexp::EXTENDED if options_str.include?('x')
options_str.gsub!(/[imx]/, '') # Now remove the three we understand options_str.gsub!(/[imx]/, '') # Now remove the three we understand
XGen::Mongo::Driver::RegexpOfHolding.new(str, options, options_str) RegexpOfHolding.new(str, options, options_str)
end end
def deserialize_string_data(buf) def deserialize_string_data(buf)
@ -254,20 +256,20 @@ class BSON
end end
def deserialize_oid_data(buf) def deserialize_oid_data(buf)
XGen::Mongo::Driver::ObjectID.new(buf.get(12)) ObjectID.new(buf.get(12))
end end
def deserialize_dbref_data(buf, key, parent) def deserialize_dbref_data(buf, key, parent)
ns = deserialize_string_data(buf) ns = deserialize_string_data(buf)
oid = deserialize_oid_data(buf) oid = deserialize_oid_data(buf)
XGen::Mongo::Driver::DBRef.new(parent, key, @db, ns, oid) DBRef.new(parent, key, @db, ns, oid)
end end
def deserialize_binary_data(buf) def deserialize_binary_data(buf)
len = buf.get_int len = buf.get_int
type = buf.get type = buf.get
len = buf.get_int if type == XGen::Mongo::Driver::Binary::SUBTYPE_BYTES len = buf.get_int if type == Binary::SUBTYPE_BYTES
XGen::Mongo::Driver::Binary.new(buf.get(len), type) Binary.new(buf.get(len), type)
end end
def serialize_eoo_element(buf) def serialize_eoo_element(buf)
@ -290,8 +292,8 @@ class BSON
bytes = val.to_a bytes = val.to_a
num_bytes = bytes.length num_bytes = bytes.length
subtype = val.respond_to?(:subtype) ? val.subtype : XGen::Mongo::Driver::Binary::SUBTYPE_BYTES subtype = val.respond_to?(:subtype) ? val.subtype : Binary::SUBTYPE_BYTES
if subtype == XGen::Mongo::Driver::Binary::SUBTYPE_BYTES if subtype == Binary::SUBTYPE_BYTES
buf.put_int(num_bytes + 4) buf.put_int(num_bytes + 4)
buf.put(subtype) buf.put(subtype)
buf.put_int(num_bytes) buf.put_int(num_bytes)
@ -419,9 +421,9 @@ class BSON
ARRAY ARRAY
when Regexp when Regexp
REGEX REGEX
when XGen::Mongo::Driver::ObjectID when ObjectID
OID OID
when XGen::Mongo::Driver::DBRef when DBRef
REF REF
when true, false when true, false
BOOLEAN BOOLEAN
@ -431,7 +433,7 @@ class BSON
OBJECT OBJECT
when Symbol when Symbol
SYMBOL SYMBOL
when XGen::Mongo::Driver::Undefined when Undefined
UNDEFINED UNDEFINED
else else
raise "Unknown type of object: #{o.class.name}" raise "Unknown type of object: #{o.class.name}"