code: def _elements_to_dict(data, position, obj_end, opts, result=None):
      
      if result is None:
          result = opts.document_class()
      end = obj_end - 1
      while position < end:
          key, value, position = _element_to_dict(data, position, obj_end, opts)
          result[key] = value
      if position != obj_end:
          raise InvalidBSON('bad object or element length')
      return result
docs: Decode a BSON document into result.