Patch Protobuf JSON Encoder / Decoder for a desired Protobuf type with to_json & from_json methods.
(
proto_type: Type[ProtoMessage],
to_json_object: Callable[[_Printer, ProtoMessage], JsonObject],
from_json_object: Callable[[_Parser, JsonObject, ProtoMessage], None],
)
| 18 | |
| 19 | |
| 20 | def _patch_proto_json_encoding( |
| 21 | proto_type: Type[ProtoMessage], |
| 22 | to_json_object: Callable[[_Printer, ProtoMessage], JsonObject], |
| 23 | from_json_object: Callable[[_Parser, JsonObject, ProtoMessage], None], |
| 24 | ) -> None: |
| 25 | """Patch Protobuf JSON Encoder / Decoder for a desired Protobuf type with to_json & from_json methods.""" |
| 26 | to_json_fn_name = "_" + uuid.uuid4().hex |
| 27 | from_json_fn_name = "_" + uuid.uuid4().hex |
| 28 | setattr(_Printer, to_json_fn_name, to_json_object) |
| 29 | setattr(_Parser, from_json_fn_name, from_json_object) |
| 30 | _WKTJSONMETHODS[proto_type.DESCRIPTOR.full_name] = [ |
| 31 | to_json_fn_name, |
| 32 | from_json_fn_name, |
| 33 | ] |
| 34 | |
| 35 | |
| 36 | def _patch_feast_value_json_encoding(): |
no outgoing calls
no test coverage detected