srkukarni closed pull request #2762: Fix IdentitySerde URL: https://github.com/apache/pulsar/pull/2762
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/pulsar-client-cpp/python/pulsar/functions/serde.py b/pulsar-client-cpp/python/pulsar/functions/serde.py index c31cb1ea3f..ee6366cf63 100644 --- a/pulsar-client-cpp/python/pulsar/functions/serde.py +++ b/pulsar-client-cpp/python/pulsar/functions/serde.py @@ -68,9 +68,19 @@ def deserialize(self, input_bytes): return pickle.loads(input_bytes) class IdentitySerDe(SerDe): - """Pickle based serializer""" + """Simple Serde that just conversion to string and back""" + def __init__(self): + self._types = [int, float, complex, str] + def serialize(self, input): - return input + if type(input) in self._types: + return str(input).encode('utf-8') + raise TypeError def deserialize(self, input_bytes): - return input_bytes \ No newline at end of file + for typ in self._types: + try: + return typ(input_bytes.decode('utf-8')) + except: + pass + raise TypeError diff --git a/pulsar-functions/instance/src/main/python/python_instance.py b/pulsar-functions/instance/src/main/python/python_instance.py index 54a7329265..cd835ede2a 100644 --- a/pulsar-functions/instance/src/main/python/python_instance.py +++ b/pulsar-functions/instance/src/main/python/python_instance.py @@ -293,7 +293,7 @@ def process_result(self, output, msg): if self.producer is None: self.setup_producer() try: - output_bytes = bytes(self.output_serde.serialize(output)) + output_bytes = self.output_serde.serialize(output) except: self.current_stats.nserialization_exceptions += 1 self.total_stats.nserialization_exceptions += 1 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services