8000 Update __init__.py · rpgod/python-betterproto@6053a70 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6053a70

Browse files
authored
Update __init__.py
Base64 encoded bytes only for Json
1 parent 13d6565 commit 6053a70

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/betterproto/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ def FromString(cls: Type[T], data: bytes) -> T:
10441044
return cls().parse(data)
10451045

10461046
def to_dict(
1047-
self, casing: Casing = Casing.CAMEL, include_default_values: bool = False
1047+
self, casing: Casing = Casing.CAMEL, include_default_values: bool = False,b64:bool=False
10481048
) -> Dict[str, Any]:
10491049
"""
10501050
Returns a JSON serializable dict representation of this object.
@@ -1143,12 +1143,12 @@ def to_dict(
11431143
elif meta.proto_type == TYPE_BYTES:
11441144
if field_is_repeated:
11451145
output[cased_name] = [
1146-
b64encode(b).decode("utf8") for b in value
1146+
b if not b64 else b64encode(b).decode("utf8") for b in value
11471147
]
11481148
elif value is None and include_default_values:
11491149
output[cased_name] = value
11501150
else:
1151-
output[cased_name] = b64encode(value).decode("utf8")
1151+
output[cased_name] =v if not b64 else b64encode(value).decode("utf8")
11521152
elif meta.proto_type == TYPE_ENUM:
11531153
if field_is_repeated:
11541154
enum_class = field_types[field_name].__args__[0]
@@ -1264,7 +1264,7 @@ def to_json(
12641264
self,
12651265
indent: Union[None, int, str] = None,
12661266
include_default_values: bool = False,
1267-
casing: Casing = Casing.CAMEL,
1267+
casing: Casing = Casing.CAMEL
12681268
) -> str:
12691269
"""A helper function to parse the message instance into its JSON
12701270
representation.
@@ -1293,7 +1293,7 @@ def to_json(
12931293
The JSON representation of the message.
12941294
"""
12951295
return json.dumps(
1296-
self.to_dict(include_default_values=include_default_values, casing=casing),
1296+
self.to_dict(include_default_values=include_default_values, casing=casing,b64=True),
12971297
indent=indent,
12981298
)
12991299

0 commit comments

Comments
 (0)
0