lib/bson/bson_ruby.rb in bson-1.0.9 vs lib/bson/bson_ruby.rb in bson-1.1

- old
+ new

@@ -42,10 +42,11 @@ NUMBER_LONG = 18 MAXKEY = 127 def initialize @buf = ByteBuffer.new + @encoder = BSON_RUBY end if RUBY_VERSION >= '1.9' NULL_BYTE = "\0".force_encoding('binary').freeze UTF8_ENCODING = Encoding.find('utf-8') @@ -301,11 +302,11 @@ end def deserialize_object_data(buf) size = buf.get_int buf.position -= 4 - object = BSON_CODER.new().deserialize(buf.get(size)) + object = @encoder.new().deserialize(buf.get(size)) if object.has_key? "$ref" DBRef.new(object["$ref"], object["$id"]) else object end @@ -356,11 +357,11 @@ code = code.pack("C*") end scope_size = buf.get_int buf.position -= 4 - scope = BSON_CODER.new().deserialize(buf.get(scope_size)) + scope = @encoder.new().deserialize(buf.get(scope_size)) Code.new(encoded_str(code), scope) end def deserialize_oid_data(buf) @@ -450,11 +451,11 @@ end def serialize_object_element(buf, key, val, check_keys, opcode=OBJECT) buf.put(opcode) self.class.serialize_key(buf, key) - buf.put_array(BSON_CODER.new.serialize(val, check_keys).to_a) + buf.put_array(@encoder.new.serialize(val, check_keys).to_a) end def serialize_array_element(buf, key, val, check_keys) # Turn array into hash with integer indices as keys h = BSON::OrderedHash.new @@ -525,13 +526,13 @@ # Make a hole for the length len_pos = buf.position buf.put_int(0) - buf.put_int(val.length + 1) - self.class.serialize_cstr(buf, val) - buf.put_array(BSON_CODER.new.serialize(val.scope).to_a) + buf.put_int(val.code.length + 1) + self.class.serialize_cstr(buf, val.code) + buf.put_array(@encoder.new.serialize(val.scope).to_a) end_pos = buf.position buf.put_int(end_pos - len_pos, len_pos) buf.position = end_pos end @@ -562,11 +563,9 @@ STRING when Array ARRAY when Regexp REGEX - when ObjectID - OID when ObjectId OID when DBRef REF when true, false