summaryrefslogtreecommitdiffstats
path: root/src/publisher
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2016-08-03 16:21:12 +0300
committerYaroslav Brustinov <ybrustin@cisco.com>2016-08-03 16:21:12 +0300
commit0f863b48e742ecd6b6dd522803e95a528024bbc9 (patch)
tree81798d3fb9d40ee41efbb41d69170c752a5c3a5f /src/publisher
parent3159743120d9e1033c5ed809c1031b814204fd8f (diff)
parent0ccbb8ff779d4e905fc4fea5d2570f6e72821b0e (diff)
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'src/publisher')
-rw-r--r--src/publisher/trex_publisher.cpp26
-rw-r--r--src/publisher/trex_publisher.h7
2 files changed, 29 insertions, 4 deletions
diff --git a/src/publisher/trex_publisher.cpp b/src/publisher/trex_publisher.cpp
index f56d56df..67670593 100644
--- a/src/publisher/trex_publisher.cpp
+++ b/src/publisher/trex_publisher.cpp
@@ -20,6 +20,7 @@ limitations under the License.
*/
#include "trex_publisher.h"
+#include "trex_rpc_zip.h"
#include <zmq.h>
#include <assert.h>
#include <sstream>
@@ -73,13 +74,32 @@ TrexPublisher::Delete(){
void
-TrexPublisher::publish_json(const std::string &s){
+TrexPublisher::publish_json(const std::string &s, uint32_t zip_threshold){
+
if (m_publisher) {
- int size = zmq_send (m_publisher, s.c_str(), s.length(), 0);
- assert(size == s.length());
+ if ( (zip_threshold != 0) && (s.size() > zip_threshold) ) {
+ publish_zipped_json(s);
+ } else {
+ publish_raw_json(s);
+ }
}
}
+void
+TrexPublisher::publish_zipped_json(const std::string &s) {
+ std::string compressed_msg;
+
+ TrexRpcZip::compress(s, compressed_msg);
+ int size = zmq_send (m_publisher, compressed_msg.c_str(), compressed_msg.length(), 0);
+ assert(size == compressed_msg.length());
+}
+
+void
+TrexPublisher::publish_raw_json(const std::string &s) {
+ int size = zmq_send (m_publisher, s.c_str(), s.length(), 0);
+ assert(size == s.length());
+}
+
void
TrexPublisher::publish_event(event_type_e type, const Json::Value &data) {
Json::FastWriter writer;
diff --git a/src/publisher/trex_publisher.h b/src/publisher/trex_publisher.h
index 1d283478..fb7226c4 100644
--- a/src/publisher/trex_publisher.h
+++ b/src/publisher/trex_publisher.h
@@ -38,7 +38,7 @@ public:
virtual bool Create(uint16_t port, bool disable);
virtual void Delete();
- virtual void publish_json(const std::string &s);
+ virtual void publish_json(const std::string &s, uint32_t zip_threshold = MSG_COMPRESS_THRESHOLD);
enum event_type_e {
EVENT_PORT_STARTED = 0,
@@ -71,9 +71,14 @@ public:
private:
void show_zmq_last_error(const std::string &err);
+ void publish_zipped_json(const std::string &s);
+ void publish_raw_json(const std::string &s);
+
private:
void * m_context;
void * m_publisher;
+
+ static const int MSG_COMPRESS_THRESHOLD = 256;
};
#endif /* __TREX_PUBLISHER_H__ */