You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tubemq.apache.org by gx...@apache.org on 2020/07/03 13:42:36 UTC

[incubator-tubemq] branch tubemq-client-cpp updated (1422dbf -> bfa239e)

This is an automated email from the ASF dual-hosted git repository.

gxcheng pushed a change to branch tubemq-client-cpp
in repository https://gitbox.apache.org/repos/asf/incubator-tubemq.git.


 discard 1422dbf  [TUBEMQ-267]Create C/C++ Message class (#182)
    omit 40332e3  [TUBEMQ-266] Add open-source-parsers/jsoncpp as submodule (#178)
     new a7d43f4  [TUBEMQ-267]Create C/C++ Message class (#182)
     new bfa239e  [TUBEMQ-266] Add Tencent/rapidjson as submodule

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (1422dbf)
            \
             N -- N -- N   refs/heads/tubemq-client-cpp (bfa239e)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .gitmodules                                                 | 8 ++++----
 tubemq-client-twins/tubemq-client-cpp/third_party/jsoncpp   | 1 -
 tubemq-client-twins/tubemq-client-cpp/third_party/rapidjson | 1 +
 3 files changed, 5 insertions(+), 5 deletions(-)
 delete mode 160000 tubemq-client-twins/tubemq-client-cpp/third_party/jsoncpp
 create mode 160000 tubemq-client-twins/tubemq-client-cpp/third_party/rapidjson


[incubator-tubemq] 02/02: [TUBEMQ-266] Add Tencent/rapidjson as submodule

Posted by gx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gxcheng pushed a commit to branch tubemq-client-cpp
in repository https://gitbox.apache.org/repos/asf/incubator-tubemq.git

commit bfa239ecc3df058a0a1b69078309441589a50b49
Author: Guangxu Cheng <gx...@apache.org>
AuthorDate: Fri Jul 3 21:41:55 2020 +0800

    [TUBEMQ-266] Add Tencent/rapidjson as submodule
---
 .gitmodules                                                 | 4 ++++
 pom.xml                                                     | 2 ++
 tubemq-client-twins/tubemq-client-cpp/.gitmodules           | 3 ---
 tubemq-client-twins/tubemq-client-cpp/third_party/rapidjson | 1 +
 4 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..417049c
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,4 @@
+[submodule "tubemq-client-twins/tubemq-client-cpp/third_party/rapidjson"]
+	path = tubemq-client-twins/tubemq-client-cpp/third_party/rapidjson
+	url = https://github.com/Tencent/rapidjson.git
+	tag = v1.1.0
diff --git a/pom.xml b/pom.xml
index df2955b..73b3b22 100644
--- a/pom.xml
+++ b/pom.xml
@@ -261,6 +261,8 @@
                         <exclude>resources/assets/lib/**</exclude>
                         <exclude>resources/assets/public/**</exclude>
                         <exclude>DISCLAIMER-WIP</exclude>
+
+                        <exclude>**/tubemq-client-twins/tubemq-client-cpp/third_party/**</exclude>
                     </excludes>
                 </configuration>
             </plugin>
diff --git a/tubemq-client-twins/tubemq-client-cpp/.gitmodules b/tubemq-client-twins/tubemq-client-cpp/.gitmodules
deleted file mode 100644
index b9a6c24..0000000
--- a/tubemq-client-twins/tubemq-client-cpp/.gitmodules
+++ /dev/null
@@ -1,3 +0,0 @@
-[submodule "third_party/jsoncpp"]
-	path = third_party/jsoncpp
-	url = https://github.com/open-source-parsers/jsoncpp.git
diff --git a/tubemq-client-twins/tubemq-client-cpp/third_party/rapidjson b/tubemq-client-twins/tubemq-client-cpp/third_party/rapidjson
new file mode 160000
index 0000000..f54b0e4
--- /dev/null
+++ b/tubemq-client-twins/tubemq-client-cpp/third_party/rapidjson
@@ -0,0 +1 @@
+Subproject commit f54b0e47a08782a6131cc3d60f94d038fa6e0a51


[incubator-tubemq] 01/02: [TUBEMQ-267]Create C/C++ Message class (#182)

Posted by gx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gxcheng pushed a commit to branch tubemq-client-cpp
in repository https://gitbox.apache.org/repos/asf/incubator-tubemq.git

commit a7d43f49afde4e0ec4c79493847e07ca2d36da9d
Author: gosonzhang <go...@tencent.com>
AuthorDate: Fri Jul 3 21:38:50 2020 +0800

    [TUBEMQ-267]Create C/C++ Message class (#182)
---
 .../tubemq-client-cpp/inc/message.h                |  78 +++++++
 .../tubemq-client-cpp/src/message.cc               | 249 +++++++++++++++++++++
 2 files changed, 327 insertions(+)

diff --git a/tubemq-client-twins/tubemq-client-cpp/inc/message.h b/tubemq-client-twins/tubemq-client-cpp/inc/message.h
new file mode 100644
index 0000000..20d7fcf
--- /dev/null
+++ b/tubemq-client-twins/tubemq-client-cpp/inc/message.h
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+      
+#ifndef _TUBEMQ_CLIENT_MESSAGE_H_
+#define _TUBEMQ_CLIENT_MESSAGE_H_
+
+
+#include <list>
+#include <map>
+#include <string>
+#include <stdio.h>
+
+
+namespace tubemq {
+
+using namespace std;
+
+class Message {
+ public:
+  Message();
+  Message(const Message& target);
+  Message(const string& topic, const char* data, int datalen);
+  virtual ~Message();
+  Message& operator=(const Message& target);
+  const long GetMessageId() const;
+  void SetMessageId(long message_id);
+  const string& GetTopic() const;
+  void SetTopic(const string& topic);
+  const char* GetData() const;
+  int GetDataLength() const;
+  void setData(const char* data, int datalen);
+  const int GetFlag() const;
+  void SetFlag(int flag);
+  const map<string, string>& GetProperties() const;
+  int GetProperties(string& attribute);
+  bool HasProperty(const string& key);
+  bool GetProperty(const string& key, string& value);
+  bool GetFilterItem(string& value);
+  bool AddProperty(string& err_info, const string& key, const string& value);  
+
+ private:
+  void clearData();
+  void copyData(const char* data, int datalen);  
+  void copyProperties(const map<string, string>& properties);
+
+  
+ private:
+  string topic_;
+  char* data_;
+  int   datalen_;
+  long  message_id_;
+  int   flag_;  
+  map<string, string> properties_;
+};
+
+}
+
+
+
+
+#endif
+
diff --git a/tubemq-client-twins/tubemq-client-cpp/src/message.cc b/tubemq-client-twins/tubemq-client-cpp/src/message.cc
new file mode 100644
index 0000000..c5162e3
--- /dev/null
+++ b/tubemq-client-twins/tubemq-client-cpp/src/message.cc
@@ -0,0 +1,249 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <sstream> 
+#include <string.h> 
+
+#include "message.h"
+#include "utils.h"
+#include "const_config.h"
+
+
+namespace tubemq {
+
+
+// message flag's properties settings
+static const int kMsgFlagIncProperties = 0x01;
+// reserved property key Filter Item
+static const string kRsvPropKeyFilterItem = "$msgType$";
+// reserved property key message send time
+static const string kRsvPropKeyMsgTime = "$msgTime$";
+
+
+Message::Message() {
+  this->topic_      = "";
+  this->flag_       = 0;
+  this->message_id_ = config::kInvalidValue;
+  this->data_       = NULL;
+  this->datalen_    = 0;
+  this->properties_.clear();
+}
+
+Message::Message(const Message& target) {
+  this->topic_      = target.topic_;
+  this->message_id_ = target.message_id_;
+  copyData(target.data_, target.datalen_);
+  copyProperties(target.properties_);
+  this->flag_       = target.flag_;
+}
+
+Message::Message(const string& topic, const char* data, int datalen) {
+  this->topic_      = topic;
+  this->flag_       = 0;
+  this->message_id_ = config::kInvalidValue;
+  copyData(data, datalen);
+  this->properties_.clear();
+}
+
+Message::~Message() {
+  clearData();
+}
+
+Message& Message::operator=(const Message& target) {
+  if (this == &target) 
+    return *this;
+  this->topic_      = target.topic_;
+  this->message_id_ = target.message_id_;
+  clearData();
+  copyData(target.data_, target.datalen_);
+  copyProperties(target.properties_);
+  this->flag_       = target.flag_;
+  return *this;
+}
+
+const long Message::GetMessageId() const {
+  return this->message_id_;
+}
+
+void Message::SetMessageId(long message_id) {
+  this->message_id_ = message_id;
+}
+
+const string& Message::GetTopic() const {
+  return this->topic_;
+}
+
+void Message::SetTopic(const string& topic) {
+  this->topic_ = topic;
+}
+
+const char* Message::GetData() const {
+  return this->data_;
+}
+
+int Message::GetDataLength() const {
+  return this->datalen_;
+}
+
+void Message::setData(const char* data, int datalen) {
+  clearData();
+  copyData(data, datalen);
+}
+
+const int Message::GetFlag() const {
+  return this->flag_;
+}
+
+void Message::SetFlag(int flag) {
+  this->flag_ = flag;
+}
+
+const map<string, string>& Message::GetProperties() const {
+  return this->properties_;
+}
+
+int Message::GetProperties(string& attribute) {
+  attribute.clear();
+  map<string, string>::iterator it_map;
+  for (it_map = this->properties_.begin(); it_map != this->properties_.end(); ++it_map) {
+    if (!attribute.empty()) {
+      attribute += delimiter::kDelimiterComma;
+    }
+    attribute += it_map->first;
+    attribute += delimiter::kDelimiterEqual;
+    attribute += it_map->second;
+  }
+  return attribute.length();
+}
+
+bool Message::HasProperty(const string& key) {
+  map<string, string>::iterator it_map;
+  string trimed_key = Utils::Trim(key);
+  if (!trimed_key.empty()) {
+    it_map = this->properties_.find(trimed_key);
+    if (it_map != this->properties_.end()) {
+      return true;
+    }
+  }
+  return false;  
+}
+
+bool Message::GetProperty(const string& key, string& value) {
+  map<string, string>::iterator it_map;
+  string trimed_key = Utils::Trim(key);
+  if (!trimed_key.empty()) {
+    it_map = this->properties_.find(trimed_key);
+    if (it_map != this->properties_.end()) {
+      value = it_map->second;
+      return true;
+    }
+  }
+  return false;  
+}
+
+bool Message::GetFilterItem(string& value) {
+  return GetProperty(kRsvPropKeyFilterItem, value);
+}
+
+bool Message::AddProperty(string& err_info, const string& key, const string& value) {
+  string trimed_key = Utils::Trim(key);
+  string trimed_value = Utils::Trim(value);
+  if (trimed_key.empty() || trimed_value.empty()) {
+    err_info = "Not allowed null value of parmeter key or value";
+    return false;
+  }
+  if ((string::npos != trimed_key.find(delimiter::kDelimiterComma)) 
+    ||(string::npos != trimed_key.find(delimiter::kDelimiterEqual))) {
+    stringstream ss;
+    ss << "Reserved token '";
+    ss << delimiter::kDelimiterComma;
+    ss << "' or '";
+    ss << delimiter::kDelimiterEqual;
+    ss << "' in parmeter key!";
+    err_info = ss.str();
+    return false;
+  }
+  if ((string::npos != trimed_value.find(delimiter::kDelimiterComma)) 
+    ||(string::npos != trimed_value.find(delimiter::kDelimiterEqual))) {
+    stringstream ss;
+    ss << "Reserved token '";
+    ss << delimiter::kDelimiterComma;
+    ss << "' or '";
+    ss << delimiter::kDelimiterEqual;
+    ss << "' in parmeter value!";
+    err_info = ss.str();
+    return false;
+  }
+  if(trimed_key == kRsvPropKeyFilterItem 
+    || trimed_key == kRsvPropKeyMsgTime) {
+    stringstream ss;
+    ss << "Reserved token '";
+    ss << kRsvPropKeyFilterItem;
+    ss << "' or '";
+    ss << kRsvPropKeyMsgTime;
+    ss << "' must not be used in parmeter key!";
+    err_info = ss.str();
+    return false;
+  }
+  // add key and value
+  this->properties_[trimed_key] = trimed_value;
+  if (!this->properties_.empty()) {
+      this->flag_ |= kMsgFlagIncProperties;
+  }
+  err_info = "Ok";
+  return true;
+}
+
+void Message::clearData() {
+  if (this->data_ != NULL) {
+    delete[] this->data_;
+    this->data_ = NULL;
+    this->datalen_ = 0;
+  }
+}
+
+void Message::copyData(const char* data, int datalen) {
+  if (data == NULL) {
+    this->data_ = NULL;
+    this->datalen_ = 0;
+  } else {
+    this->datalen_ = datalen;
+    this->data_ = new char[datalen];
+    memset(this->data_, 0, datalen);
+    memcpy(this->data_, data, datalen);
+  }
+}
+
+void Message::copyProperties(const map<string, string>& properties) {
+  this->properties_.clear();
+  map<string, string>::const_iterator it_map;
+  for (it_map = properties.begin(); it_map != properties.end(); ++it_map) {
+    this->properties_[it_map->first] = it_map->second;
+  }
+  if (!this->properties_.empty()) {
+    this->flag_ |= kMsgFlagIncProperties;
+  }
+}
+
+
+}
+
+
+
+