Fixed DBRef (de)serialization

This commit is contained in:
Jim Menard 2009-01-09 11:56:30 -05:00
parent 2513084324
commit 5d71afa737

View File

@ -107,37 +107,37 @@ class BSON
type = @buf.get type = @buf.get
case type case type
when STRING, CODE when STRING, CODE
key = deserialize_element_name(@buf) key = deserialize_cstr(@buf)
doc[key] = deserialize_string_data(@buf) doc[key] = deserialize_string_data(@buf)
when NUMBER when NUMBER
key = deserialize_element_name(@buf) key = deserialize_cstr(@buf)
doc[key] = deserialize_number_data(@buf) doc[key] = deserialize_number_data(@buf)
when NUMBER_INT when NUMBER_INT
key = deserialize_element_name(@buf) key = deserialize_cstr(@buf)
doc[key] = deserialize_number_int_data(@buf) doc[key] = deserialize_number_int_data(@buf)
when OID when OID
key = deserialize_element_name(@buf) key = deserialize_cstr(@buf)
doc[key] = deserialize_oid_data(@buf) doc[key] = deserialize_oid_data(@buf)
when ARRAY when ARRAY
key = deserialize_element_name(@buf) key = deserialize_cstr(@buf)
doc[key] = deserialize_array_data(@buf) doc[key] = deserialize_array_data(@buf)
when REGEX when REGEX
key = deserialize_element_name(@buf) key = deserialize_cstr(@buf)
doc[key] = deserialize_regex_data(@buf) doc[key] = deserialize_regex_data(@buf)
when OBJECT when OBJECT
key = deserialize_element_name(@buf) key = deserialize_cstr(@buf)
doc[key] = deserialize_object_data(@buf) doc[key] = deserialize_object_data(@buf)
when BOOLEAN when BOOLEAN
key = deserialize_element_name(@buf) key = deserialize_cstr(@buf)
doc[key] = deserialize_boolean_data(@buf) doc[key] = deserialize_boolean_data(@buf)
when DATE when DATE
key = deserialize_element_name(@buf) key = deserialize_cstr(@buf)
doc[key] = deserialize_date_data(@buf) doc[key] = deserialize_date_data(@buf)
when NULL when NULL
key = deserialize_element_name(@buf) key = deserialize_cstr(@buf)
doc[key] = nil doc[key] = nil
when REF when REF
key = deserialize_element_name(@buf) key = deserialize_cstr(@buf)
doc[key] = deserialize_dbref_data(@buf) doc[key] = deserialize_dbref_data(@buf)
when BINARY, UNDEFINED, SYMBOL, CODE_W_SCOPE when BINARY, UNDEFINED, SYMBOL, CODE_W_SCOPE
# TODO # TODO
@ -197,8 +197,8 @@ class BSON
end end
def deserialize_regex_data(buf) def deserialize_regex_data(buf)
str = deserialize_element_name(buf) str = deserialize_cstr(buf)
options_str = deserialize_element_name(buf) options_str = deserialize_cstr(buf)
options = 0 options = 0
options |= Regexp::IGNORECASE if options_str.include?('i') options |= Regexp::IGNORECASE if options_str.include?('i')
options |= Regexp::MULTILINE if options_str.include?('m') options |= Regexp::MULTILINE if options_str.include?('m')
@ -217,7 +217,7 @@ class BSON
end end
def deserialize_dbref_data(buf) def deserialize_dbref_data(buf)
ns = deserialize_string_data(buf) ns = deserialize_cstr(buf)
oid = deserialize_oid_data(buf) oid = deserialize_oid_data(buf)
# TODO fix parent, field_name, db of DBRef. Does that need to be done here # TODO fix parent, field_name, db of DBRef. Does that need to be done here
# or by the caller? # or by the caller?
@ -234,7 +234,9 @@ class BSON
end end
def serialize_dbref_element(buf, key, val) def serialize_dbref_element(buf, key, val)
serialize_string_element(buf, key, val.namespace, REF) buf.put(REF)
self.class.serialize_cstr(buf, key)
self.class.serialize_cstr(buf, val.namespace)
buf.put_array(val.object_id.to_a) buf.put_array(val.object_id.to_a)
end end
@ -317,7 +319,7 @@ class BSON
buf.position = end_pos buf.position = end_pos
end end
def deserialize_element_name(buf) def deserialize_cstr(buf)
chars = "" chars = ""
while 1 while 1
b = buf.get b = buf.get