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

Doesn't convert ZERO value of enum and False of boolean #11

Open dakzh opened 8 years ago

dakzh commented 8 years ago

enum SomeType { ZERO_VALUE = 0; ONE_VALUE = 1; }

message Test { SomeType type = 1; bool is_test = 2; }

If we try to covert Test object with values SomeType.ZERO_VALUE and is_test is false from protobuf, then our dict will be empty

Sergii-Makarevych commented 7 years ago

Right. Same issue here with False values - output dict does not contain this field.

aalba6675 commented 7 years ago

May be a low level protobuf issue: if you just

print(pb_my_message)

enum members of value 0 also don't show up.

Also MessageToJson(pb_my_message) also won't have keys whose value is 0. It's weird.

Sergii-Makarevych commented 7 years ago

It does show up. But missed after protobuf_to_dict method

jclosure commented 3 years ago

+1 same issue still in the go forward fork: https://github.com/kaporzhu/protobuf-to-dict. We should fix this, because it makes the dictionary output not fully representative of a protobuf.