Skip to content

Commit

Permalink
feat: add preserving_proto_field_name passthrough in MessageMeta.to_d…
Browse files Browse the repository at this point in the history
…ict (#211)
  • Loading branch information
software-dov committed Mar 12, 2021
1 parent 36c0c56 commit 7675a0c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions proto/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ def from_json(cls, payload, *, ignore_unknown_fields=False) -> "Message":
Parse(payload, instance._pb, ignore_unknown_fields=ignore_unknown_fields)
return instance

def to_dict(cls, instance, *, use_integers_for_enums=True) -> "Message":
def to_dict(
cls, instance, *, use_integers_for_enums=True, preserving_proto_field_name=True
) -> "Message":
"""Given a message instance, return its representation as a python dict.
Args:
Expand All @@ -378,6 +380,9 @@ def to_dict(cls, instance, *, use_integers_for_enums=True) -> "Message":
use_integers_for_enums (Optional(bool)): An option that determines whether enum
values should be represented by strings (False) or integers (True).
Default is True.
preserving_proto_field_name (Optional(bool)): An option that
determines whether field name representations preserve
proto case (snake_case) or use lowerCamelCase. Default is True.
Returns:
dict: A representation of the protocol buffer using pythonic data structures.
Expand All @@ -387,7 +392,7 @@ def to_dict(cls, instance, *, use_integers_for_enums=True) -> "Message":
return MessageToDict(
cls.pb(instance),
including_default_value_fields=True,
preserving_proto_field_name=True,
preserving_proto_field_name=preserving_proto_field_name,
use_integers_for_enums=use_integers_for_enums,
)

Expand Down

0 comments on commit 7675a0c

Please sign in to comment.