'Converts the (protobuf) result from an API call into a dict, for
easier introspection.'

def toDict(self, protoObj):

    iterable = False
    if isinstance(protoObj, RepeatedCompositeFieldContainer):
        iterable = True
    else:
        protoObj = [protoObj]
    retlist = []
    for po in protoObj:
        msg = dict()
        for (fielddesc, value) in po.ListFields():
            if ((fielddesc.type == descriptor.FieldDescriptor.TYPE_GROUP) or isinstance(value, RepeatedCompositeFieldContainer) or isinstance(value, Message)):
                msg[fielddesc.name] = self.toDict(value)
            else:
                msg[fielddesc.name] = value
        retlist.append(msg)
    if (not iterable):
        if (len(retlist) > 0):
            return retlist[0]
        else:
            return None
    return retlist
