def _to_dict(pb):
    # Takes a protocol buffer (pb) and transforms it into a dict of more
    # common Python types.
    out = {}
    for name in pb.fields():
        if name not in pb:
            continue
        value = getattr(pb, name)
        def maybe_recurse(v):
            if isinstance(v, palm.ProtoBase):
                return _to_dict(v)
            return v
        if isinstance(value, palm.RepeatedSequence):
            value = [maybe_recurse(v) for v in iter(value)]
        else:
            value = maybe_recurse(value)
        out[name] = value
    return out


# Testing Code Below
# ==================
# XXX hack - can't define it in __main__ below
dataset/ETHPy150Open dieseldev/diesel/diesel/protocols/riak.py/_to_dict/original