summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim O'Shea <tim.oshea753@gmail.com>2014-12-28 12:47:07 +0100
committerTim O'Shea <tim.oshea753@gmail.com>2014-12-28 12:47:07 +0100
commit232a9bc8f9e05671e54fc204ed209dc8e7948f7f (patch)
tree70fa626b87b542a6af3803d08f9055b8c9e85594
parent585cc65be340fe1ed4c99ff397c3d71f49b621c5 (diff)
zmq: adding header information
-rw-r--r--gr-zeromq/lib/tag_headers.cc24
1 files changed, 23 insertions, 1 deletions
diff --git a/gr-zeromq/lib/tag_headers.cc b/gr-zeromq/lib/tag_headers.cc
index c47bac7ae1..c97066629c 100644
--- a/gr-zeromq/lib/tag_headers.cc
+++ b/gr-zeromq/lib/tag_headers.cc
@@ -25,14 +25,23 @@
#include <sstream>
#include <cstring>
+#define GR_HEADER_MAGIC 0x5FF0
+#define GR_HEADER_VERSION 0x01
+
namespace gr {
namespace zeromq {
std::string
gen_tag_header(uint64_t &offset, std::vector<gr::tag_t> &tags) {
+ uint16_t header_magic = GR_HEADER_MAGIC;
+ uint8_t header_version = GR_HEADER_VERSION;
+
std::stringstream ss;
size_t ntags = tags.size();
+ ss.write( reinterpret_cast< const char* >( &header_magic ), sizeof(uint16_t) );
+ ss.write( reinterpret_cast< const char* >( &header_version ), sizeof(uint8_t) );
+
ss.write( reinterpret_cast< const char* >( &offset ), sizeof(uint64_t) ); // offset
ss.write( reinterpret_cast< const char* >( &ntags ), sizeof(size_t) ); // num tags
std::stringbuf sb("");
@@ -55,10 +64,23 @@ namespace gr {
std::istringstream iss( buf_in );
size_t rcv_ntags;
+
+ uint16_t header_magic;
+ uint8_t header_version;
+
+ iss.read( (char*)&header_magic, sizeof(uint16_t ) );
+ iss.read( (char*)&header_version, sizeof(uint8_t ) );
+ if(header_magic != GR_HEADER_MAGIC){
+ throw std::runtime_error("gr header magic does not match!");
+ }
+ if(header_version != 1){
+ throw std::runtime_error("gr header version too high!");
+ }
+
iss.read( (char*)&offset_out, sizeof(uint64_t ) );
iss.read( (char*)&rcv_ntags, sizeof(size_t ) );
//std::cout << "RX TAGS: (offset="<<offset_out<<" ntags="<<rcv_ntags<<")\n";
- int rd_offset = sizeof(uint64_t) + sizeof(size_t);
+ int rd_offset = sizeof(uint16_t) + sizeof(uint8_t) + sizeof(uint64_t) + sizeof(size_t);
std::stringbuf sb( iss.str().substr(rd_offset) );
for(size_t i=0; i<rcv_ntags; i++){