benhodgson / protobuf-to-dict

A small Python library for creating dicts from protocol buffers. Useful as an intermediate step before serialization (e.g. to JSON).
Other
226 stars 108 forks source link

Using enum labels wasn't recursive #2

Closed Tristramg closed 11 years ago

Tristramg commented 11 years ago

I fixed that by defining the recursion inside the protobuf_to_dict function

benhodgson commented 11 years ago

@CanalTP Good catch, thanks :). Instead of modifying the mutable type_callable_map value on line 37, however, it's probably better to do something like this around line 43 to avoid leaking state between protobuf_to_dict calls:

if field.type == FieldDescriptor.TYPE_MESSAGE:
  type_callable = lambda pb: protobuf_to_dict(pb, type_callable_map=type_callable_map,
    use_enum_labels=use_enum_labels)
else:
  type_callable = type_callable_map[field.type]

What do you think?

Tristramg commented 11 years ago

It's fine for me :) :+1:

benhodgson commented 11 years ago

@CanalTP Merged. I’ve also released this change to the PyPI distribution as 0.0.4 :)