From commits-return-15829-archive-asf-public=cust-asf.ponee.io@pulsar.apache.org Wed Oct 10 02:55:56 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 70F4D18072F for ; Wed, 10 Oct 2018 02:55:56 +0200 (CEST) Received: (qmail 9355 invoked by uid 500); 10 Oct 2018 00:55:55 -0000 Mailing-List: contact commits-help@pulsar.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pulsar.apache.org Delivered-To: mailing list commits@pulsar.apache.org Received: (qmail 9345 invoked by uid 99); 10 Oct 2018 00:55:55 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Oct 2018 00:55:55 +0000 From: GitBox To: commits@pulsar.apache.org Subject: [GitHub] srkukarni closed pull request #2750: [python] MessageId.serialize() should return bytes instead of str Message-ID: <153913295491.32556.17845119163895837798.gitbox@gitbox.apache.org> Date: Wed, 10 Oct 2018 00:55:54 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit srkukarni closed pull request #2750: [python] MessageId.serialize() should return bytes instead of str URL: https://github.com/apache/pulsar/pull/2750 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/__init__.py b/pulsar-client-cpp/python/pulsar/__init__.py index 6849ecc245..5f28efb741 100644 --- a/pulsar-client-cpp/python/pulsar/__init__.py +++ b/pulsar-client-cpp/python/pulsar/__init__.py @@ -107,6 +107,7 @@ def send_callback(res, msg): import re _retype = type(re.compile('x')) + class MessageId: """ Represents a message id @@ -120,18 +121,18 @@ class MessageId: def serialize(self): """ - Returns a string representation of the message id. - This string can be stored and later deserialized. + Returns a bytes representation of the message id. + This bytes sequence can be stored and later deserialized. """ return self._msg_id.serialize() @staticmethod - def deserialize(message_id_str): + def deserialize(message_id_bytes): """ Deserialize a message id object from a previously - serialized string. + serialized bytes sequence. """ - return _pulsar.MessageId.deserialize(message_id_str) + return _pulsar.MessageId.deserialize(message_id_bytes) class Message: diff --git a/pulsar-client-cpp/python/pulsar_test.py b/pulsar-client-cpp/python/pulsar_test.py index d5163bcddf..7fb8f41156 100755 --- a/pulsar-client-cpp/python/pulsar_test.py +++ b/pulsar-client-cpp/python/pulsar_test.py @@ -753,6 +753,12 @@ def test_topics_pattern_consumer(self): pass client.close() + def test_message_id(self): + s = MessageId.earliest.serialize() + self.assertEqual(MessageId.deserialize(s), MessageId.earliest) + + s = MessageId.latest.serialize() + self.assertEqual(MessageId.deserialize(s), MessageId.latest) def _check_value_error(self, fun): try: diff --git a/pulsar-client-cpp/python/src/message.cc b/pulsar-client-cpp/python/src/message.cc index 1d1ee235c5..42322490e1 100644 --- a/pulsar-client-cpp/python/src/message.cc +++ b/pulsar-client-cpp/python/src/message.cc @@ -26,10 +26,34 @@ std::string MessageId_str(const MessageId& msgId) { return ss.str(); } -std::string MessageId_serialize(const MessageId& msgId) { +bool MessageId_eq(const MessageId& a, const MessageId& b) { + return a == b; +} + +bool MessageId_ne(const MessageId& a, const MessageId& b) { + return a != b; +} + +bool MessageId_lt(const MessageId& a, const MessageId& b) { + return a < b; +} + +bool MessageId_le(const MessageId& a, const MessageId& b) { + return a <= b; +} + +bool MessageId_gt(const MessageId& a, const MessageId& b) { + return a > b; +} + +bool MessageId_ge(const MessageId& a, const MessageId& b) { + return a >= b; +} + +boost::python::object MessageId_serialize(const MessageId& msgId) { std::string serialized; msgId.serialize(serialized); - return serialized; + return boost::python::object(boost::python::handle<>(PyBytes_FromStringAndSize(serialized.c_str(), serialized.length()))); } std::string Message_str(const Message& msg) { @@ -72,6 +96,12 @@ void export_message() { class_("MessageId") .def("__str__", &MessageId_str) + .def("__eq__", &MessageId_eq) + .def("__ne__", &MessageId_ne) + .def("__le__", &MessageId_le) + .def("__lt__", &MessageId_lt) + .def("__ge__", &MessageId_ge) + .def("__gt__", &MessageId_gt) .add_static_property("earliest", make_getter(&_MessageId_earliest)) .add_static_property("latest", make_getter(&_MessageId_latest)) .def("serialize", &MessageId_serialize) ---------------------------------------------------------------- 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: users@infra.apache.org With regards, Apache Git Services