[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 06/29: zmq: hoisting tag parsing into helpe
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 06/29: zmq: hoisting tag parsing into helper function, should now be easy to use in other zmq blocks |
Date: |
Tue, 13 Jan 2015 01:04:26 +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 169a6c796d7fd3ff5dfc5114e38e6a05000068d5
Author: Tim O'Shea <address@hidden>
Date: Mon Oct 27 18:31:03 2014 -0400
zmq: hoisting tag parsing into helper function, should now be easy to use
in other zmq blocks
---
gr-zeromq/lib/CMakeLists.txt | 1 +
gr-zeromq/lib/sub_source_impl.cc | 37 +++++++++----------------
gr-zeromq/lib/{tag_headers.h => tag_headers.cc} | 18 +++++++++++-
gr-zeromq/lib/tag_headers.h | 20 ++-----------
4 files changed, 33 insertions(+), 43 deletions(-)
diff --git a/gr-zeromq/lib/CMakeLists.txt b/gr-zeromq/lib/CMakeLists.txt
index 90cbb12..b04754e 100644
--- a/gr-zeromq/lib/CMakeLists.txt
+++ b/gr-zeromq/lib/CMakeLists.txt
@@ -43,6 +43,7 @@ list(APPEND zeromq_sources
push_sink_impl.cc
rep_sink_impl.cc
req_source_impl.cc
+ tag_headers.cc
)
#Add Windows DLL resource file if using MSVC
diff --git a/gr-zeromq/lib/sub_source_impl.cc b/gr-zeromq/lib/sub_source_impl.cc
index 6c9da1b..9276a5e 100644
--- a/gr-zeromq/lib/sub_source_impl.cc
+++ b/gr-zeromq/lib/sub_source_impl.cc
@@ -26,6 +26,7 @@
#include <gnuradio/io_signature.h>
#include "sub_source_impl.h"
+#include "tag_headers.h"
namespace gr {
namespace zeromq {
@@ -83,38 +84,26 @@ namespace gr {
d_socket->recv(&msg);
// Deserialize header data / tags
- std::istringstream iss( std::string(static_cast<char*>(msg.data()),
msg.size()));
+ std::string buf(static_cast<char*>(msg.data()), msg.size());
if(d_pass_tags){
- uint64_t rcv_offset;
- size_t rcv_ntags;
- iss.read( (char*)&rcv_offset, sizeof(uint64_t ) );
- iss.read( (char*)&rcv_ntags, sizeof(size_t ) );
- for(size_t i=0; i<rcv_ntags; i++){
- uint64_t tag_offset;
- iss.read( (char*)&tag_offset, sizeof(uint64_t ) );
- std::stringbuf sb( iss.str() );
- pmt::pmt_t key = pmt::deserialize( sb );
- pmt::pmt_t val = pmt::deserialize( sb );
- pmt::pmt_t src = pmt::deserialize( sb );
- uint64_t new_tag_offset = tag_offset + nitems_read(0) - rcv_offset;
- add_item_tag(0, new_tag_offset, key, val, src);
- iss.str(sb.str());
+ uint64_t rcv_offset;
+ std::vector<gr::tag_t> tags;
+ buf = parse_tag_header(buf, rcv_offset, tags);
+ for(size_t i=0; i<tags.size(); i++){
+ tags[i].offset -= rcv_offset - nitems_read(0);
+ add_item_tag(0, tags[i]);
+ }
}
- }
-
- // Pass sample data along
- std::vector<char> samp(iss.gcount());
- iss.read( &samp[0], iss.gcount() );
// Copy to ouput buffer and return
- if (samp.size() >= d_itemsize*d_vlen*noutput_items) {
- memcpy(out, (void *)&samp[0], d_itemsize*d_vlen*noutput_items);
+ if (buf.size() >= d_itemsize*d_vlen*noutput_items) {
+ memcpy(out, (void *)&buf[0], d_itemsize*d_vlen*noutput_items);
return noutput_items;
}
else {
- memcpy(out, (void *)&samp[0], samp.size());
- return samp.size()/(d_itemsize*d_vlen);
+ memcpy(out, (void *)&buf[0], buf.size());
+ return buf.size()/(d_itemsize*d_vlen);
}
}
else {
diff --git a/gr-zeromq/lib/tag_headers.h b/gr-zeromq/lib/tag_headers.cc
similarity index 58%
copy from gr-zeromq/lib/tag_headers.h
copy to gr-zeromq/lib/tag_headers.cc
index 0a4dfee..778ceee 100644
--- a/gr-zeromq/lib/tag_headers.h
+++ b/gr-zeromq/lib/tag_headers.cc
@@ -21,4 +21,20 @@ std::string gen_tag_header(uint64_t &offset,
std::vector<gr::tag_t> &tags){
return ss.str();
}
-
+std::string parse_tag_header(std::string &buf_in, uint64_t &offset_out,
std::vector<gr::tag_t> tags_out){
+ std::istringstream iss( buf_in );
+ size_t rcv_ntags;
+ iss.read( (char*)&offset_out, sizeof(uint64_t ) );
+ iss.read( (char*)&rcv_ntags, sizeof(size_t ) );
+ for(size_t i=0; i<rcv_ntags; i++){
+ gr::tag_t newtag;
+ iss.read( (char*)&newtag.offset, sizeof(uint64_t ) );
+ std::stringbuf sb( iss.str() );
+ newtag.key = pmt::deserialize( sb );
+ newtag.value = pmt::deserialize( sb );
+ newtag.srcid = pmt::deserialize( sb );
+ tags_out.push_back(newtag);
+ iss.str(sb.str());
+ }
+ return iss.str();
+}
diff --git a/gr-zeromq/lib/tag_headers.h b/gr-zeromq/lib/tag_headers.h
index 0a4dfee..51cb0c0 100644
--- a/gr-zeromq/lib/tag_headers.h
+++ b/gr-zeromq/lib/tag_headers.h
@@ -4,21 +4,5 @@
#include <sstream>
#include <cstring>
-std::string gen_tag_header(uint64_t &offset, std::vector<gr::tag_t> &tags){
- std::stringstream ss;
- size_t ntags = tags.size();
- 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("");
- for(size_t i=0; i<tags.size(); i++){
- ss.write( reinterpret_cast< const char* >( &tags[i].offset ),
sizeof(uint64_t) ); // offset
- sb.str("");
- pmt::serialize( tags[i].key, sb );
// key
- pmt::serialize( tags[i].value, sb );
// value
- pmt::serialize( tags[i].srcid, sb );
// srcid
- ss.write( sb.str().c_str() , sb.str().length() ); // offset
- }
- return ss.str();
-}
-
-
+std::string gen_tag_header(uint64_t &offset, std::vector<gr::tag_t> &tags);
+std::string parse_tag_header(std::string &buf_in, uint64_t &offset_out,
std::vector<gr::tag_t> tags_out);
- [Commit-gnuradio] [gnuradio] branch master updated (5cb307e -> 1581681), git, 2015/01/12
- [Commit-gnuradio] [gnuradio] 13/29: zmq: adding header information, git, 2015/01/12
- [Commit-gnuradio] [gnuradio] 11/29: zeromq: fix segfault in tag_headers, git, 2015/01/12
- [Commit-gnuradio] [gnuradio] 16/29: zmq: naming cleanup, git, 2015/01/12
- [Commit-gnuradio] [gnuradio] 17/29: zmq: pull_msg_source should be working, git, 2015/01/12
- [Commit-gnuradio] [gnuradio] 20/29: zeromq: cleanup and convert pub_msg_sink to derive from gr::block, git, 2015/01/12
- [Commit-gnuradio] [gnuradio] 23/29: zeromq: cleanup and made pull_msg_source derive from gr::block, git, 2015/01/12
- [Commit-gnuradio] [gnuradio] 07/29: zmq: all source blocks should now support tag headers, git, 2015/01/12
- [Commit-gnuradio] [gnuradio] 06/29: zmq: hoisting tag parsing into helper function, should now be easy to use in other zmq blocks,
git <=
- [Commit-gnuradio] [gnuradio] 14/29: zmq: Adding zmq pub/sub blocks for message passing, git, 2015/01/12
- [Commit-gnuradio] [gnuradio] 21/29: zeromq: cleanup and convert sub_msg_source to derive from gr::block, git, 2015/01/12
- [Commit-gnuradio] [gnuradio] 22/29: zeromq: cleanup and converted push_msg_sink to derive from gr::block, git, 2015/01/12
- [Commit-gnuradio] [gnuradio] 01/29: zmq: encoding tags into zmq stream, git, 2015/01/12
- [Commit-gnuradio] [gnuradio] 10/29: zeromq: fixups and stylistic changes before merge, git, 2015/01/12
- [Commit-gnuradio] [gnuradio] 24/29: zeromq: cleanup and converted rep_msg_sink to derive from gr::block, git, 2015/01/12
- [Commit-gnuradio] [gnuradio] 08/29: zmq: sync blocks now all support tag headers, git, 2015/01/12
- [Commit-gnuradio] [gnuradio] 12/29: zmq: stream tag passing now works, git, 2015/01/12
- [Commit-gnuradio] [gnuradio] 19/29: Merge remote-tracking branch 'osh/zmqtags' into zmq_tags, git, 2015/01/12
- [Commit-gnuradio] [gnuradio] 29/29: Merge branch 'maint', git, 2015/01/12