Use external package betterproto-rust-codec for better (de-)serialization performance (#545)
				
					
				
			* optionally use betterproto-rust-codec * monkey patch `parse` and `__bytes__`
This commit is contained in:
		| @@ -1868,6 +1868,23 @@ class Message(ABC): | ||||
|  | ||||
| Message.__annotations__ = {}  # HACK to avoid typing.get_type_hints breaking :) | ||||
|  | ||||
| # monkey patch (de-)serialization functions of class `Message` | ||||
| # with functions from `betterproto-rust-codec` if available | ||||
| try: | ||||
|     import betterproto_rust_codec | ||||
|  | ||||
|     def __parse_patch(self: T, data: bytes) -> T: | ||||
|         betterproto_rust_codec.deserialize(self, data) | ||||
|         return self | ||||
|  | ||||
|     def __bytes_patch(self) -> bytes: | ||||
|         return betterproto_rust_codec.serialize(self) | ||||
|  | ||||
|     Message.parse = __parse_patch | ||||
|     Message.__bytes__ = __bytes_patch | ||||
| except ModuleNotFoundError: | ||||
|     pass | ||||
|  | ||||
|  | ||||
| def serialized_on_wire(message: Message) -> bool: | ||||
|     """ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user