From 7675a0c8d1004f2727d64100527f2b208d305017 Mon Sep 17 00:00:00 2001 From: Dov Shlachter Date: Fri, 12 Mar 2021 10:08:16 -0800 Subject: [PATCH] feat: add preserving_proto_field_name passthrough in MessageMeta.to_dict (#211) --- proto/message.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/proto/message.py b/proto/message.py index abb8f635..8ed2a69a 100644 --- a/proto/message.py +++ b/proto/message.py @@ -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: @@ -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. @@ -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, )