|
1 | 1 | /*
|
2 |
| - Copyright (c) 2016 VOCA AS / Harald Nøkland |
| 2 | + Copyright (c) 2016 VOCA AS / Harald Nøkland |
3 | 3 |
|
4 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
5 | 5 | of this software and associated documentation files (the "Software"), to
|
@@ -36,7 +36,7 @@ namespace zmq {
|
36 | 36 | /*
|
37 | 37 | This class handles multipart messaging. It is the C++ equivalent of zmsg.h,
|
38 | 38 | which is part of CZMQ (the high-level C binding). Furthermore, it is a major
|
39 |
| - improvement compared to zmsg.hpp, which is part of the examples in the ØMQ |
| 39 | + improvement compared to zmsg.hpp, which is part of the examples in the ØMQ |
40 | 40 | Guide. Unnecessary copying is avoided by using move semantics to efficiently
|
41 | 41 | add/remove parts.
|
42 | 42 | */
|
@@ -327,6 +327,23 @@ class multipart_t
|
327 | 327 | {
|
328 | 328 | return &m_parts[index];
|
329 | 329 | }
|
| 330 | + |
| 331 | + // Get a string copy of a specific message part |
| 332 | + std::string peekstr(size_t index) const |
| 333 | + { |
| 334 | + std::string string(m_parts[index].data<char>(), m_parts[index].size()); |
| 335 | + return string; |
| 336 | + } |
| 337 | + |
| 338 | + // Peek type (fixed-size) from front |
| 339 | + template<typename T> |
| 340 | + T peektyp(size_t index) |
| 341 | + { |
| 342 | + static_assert(!std::is_same<T, std::string>::value, "Use peekstr() instead of peektyp<std::string>()"); |
| 343 | + if(sizeof(T) != m_parts.front().size()) |
| 344 | + throw std::runtime_error("Invalid type, size does not match the message size"); |
| 345 | + T type = *m_parts[index].data<T>(); |
| 346 | + } |
330 | 347 |
|
331 | 348 | // Create multipart from type (fixed-size)
|
332 | 349 | template<typename T>
|
|
0 commit comments