code: def _get_object(data, position, obj_end, opts, dummy):
      
      obj_size, end = _get_object_size(data, position, obj_end)
      if _raw_document_class(opts.document_class):
          return (opts.document_class(data[position:end + 1], opts),
                  position + obj_size)
  
      obj = _elements_to_dict(data, position + 4, end, opts)
  
      position += obj_size
      if "$ref" in obj:
          return (DBRef(obj.pop("$ref"), obj.pop("$id", None),
                        obj.pop("$db", None), obj), position)
      return obj, position
docs: Decode a BSON subdocument to opts.document_class or bson.dbref.DBRef.