commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 13/29: zmq: adding header information


From: git
Subject: [Commit-gnuradio] [gnuradio] 13/29: zmq: adding header information
Date: Tue, 13 Jan 2015 01:04:27 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 232a9bc8f9e05671e54fc204ed209dc8e7948f7f
Author: Tim O'Shea <address@hidden>
Date:   Sun Dec 28 12:47:07 2014 +0100

    zmq: adding header information
---
 gr-zeromq/lib/tag_headers.cc | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/gr-zeromq/lib/tag_headers.cc b/gr-zeromq/lib/tag_headers.cc
index c47bac7..c970666 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++){



reply via email to

[Prev in Thread] Current Thread [Next in Thread]