code: def proto_to_dict(message):
      
      if not isinstance(message, _ProtoMessageType):
          raise TypeError("Expected `message` to be a instance of protobuf message")
  
      data = {}
  
      for desc, field in message.ListFields():
          if desc.type == desc.TYPE_MESSAGE:
              if desc.label == desc.LABEL_REPEATED:
                  data[desc.name] = list(map(proto_to_dict, field))
              else:
                  data[desc.name] = proto_to_dict(field)
          else:
              data[desc.name] = list(field) if desc.label == desc.LABEL_REPEATED else field
  
      return data
docs: Converts protobuf message instance to dict
  
      :param message: protobuf message instance
      :return: parameters and their values
      :rtype: dict
      :raises: :class:`.TypeError` if ``message`` is not a proto message