pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] srkukarni closed pull request #2750: [python] MessageId.serialize() should return bytes instead of str
Date Wed, 10 Oct 2018 00:55:54 GMT
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>("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

Mime
View raw message