You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2018/12/25 12:28:22 UTC

[GitHub] ShannonDing closed pull request #36: [ISSUE #35]C-API unable to get the right message properties,such as getKeys ,getTags

ShannonDing closed pull request #36: [ISSUE #35]C-API unable to get the right message properties,such as getKeys ,getTags
URL: https://github.com/apache/rocketmq-client-cpp/pull/36
 
 
   

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/include/MQMessage.h b/include/MQMessage.h
index 9c14e541..cc65fd12 100755
--- a/include/MQMessage.h
+++ b/include/MQMessage.h
@@ -40,17 +40,17 @@ class ROCKETMQCLIENT_API MQMessage {
   MQMessage(const MQMessage& other);
   MQMessage& operator=(const MQMessage& other);
 
-  void setProperty(const std::string& name, const std::string& value);
-  std::string getProperty(const std::string& name) const;
+  void setProperty(const std::string& name, const std::string& value) ;
+  const std::string & getProperty(const std::string& name) const;
 
-  std::string getTopic() const;
+  const std::string &getTopic() const;
   void setTopic(const std::string& topic);
   void setTopic(const char* body, int len);
 
-  std::string getTags() const;
+  const std::string &getTags() const;
   void setTags(const std::string& tags);
 
-  std::string getKeys() const;
+  const std::string &getKeys() const;
   void setKeys(const std::string& keys);
   void setKeys(const std::vector<std::string>& keys);
 
@@ -63,7 +63,7 @@ class ROCKETMQCLIENT_API MQMessage {
   int getFlag() const;
   void setFlag(int flag);
 
-  std::string getBody() const;
+  const std::string &getBody() const;
   void setBody(const char* body, int len);
   void setBody(const std::string& body);
 
diff --git a/src/message/MQMessage.cpp b/src/message/MQMessage.cpp
index 5f3812e3..c8bae4b5 100755
--- a/src/message/MQMessage.cpp
+++ b/src/message/MQMessage.cpp
@@ -93,13 +93,16 @@ void MQMessage::setProperty(const string& name, const string& value) {
   m_properties[name] = value;
 }
 
-string MQMessage::getProperty(const string& name) const {
+const string & MQMessage::getProperty(const string& name) const {
   map<string, string>::const_iterator it = m_properties.find(name);
-
-  return (it == m_properties.end()) ? "" : (*it).second;
+  if(it == m_properties.end()){
+    return "";
+  }else{
+    return it->second;
+  }
 }
 
-string MQMessage::getTopic() const { return m_topic; }
+const string& MQMessage::getTopic() const { return m_topic; }
 
 void MQMessage::setTopic(const string& topic) { m_topic = topic; }
 
@@ -108,13 +111,13 @@ void MQMessage::setTopic(const char* body, int len) {
   m_topic.append(body, len);
 }
 
-string MQMessage::getTags() const { return getProperty(PROPERTY_TAGS); }
+const string& MQMessage::getTags() const { return getProperty(PROPERTY_TAGS); }
 
 void MQMessage::setTags(const string& tags) {
   setProperty(PROPERTY_TAGS, tags);
 }
 
-string MQMessage::getKeys() const { return getProperty(PROPERTY_KEYS); }
+const string& MQMessage::getKeys() const { return getProperty(PROPERTY_KEYS); }
 
 void MQMessage::setKeys(const string& keys) {
   setProperty(PROPERTY_KEYS, keys);
@@ -174,7 +177,7 @@ int MQMessage::getFlag() const { return m_flag; }
 
 void MQMessage::setFlag(int flag) { m_flag = flag; }
 
-string MQMessage::getBody() const { return m_body; }
+const string& MQMessage::getBody() const { return m_body; }
 
 void MQMessage::setBody(const char* body, int len) {
   m_body.clear();


 

----------------------------------------------------------------
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