diff options
| author | Andrew Stitcher <astitcher@apache.org> | 2007-08-31 18:20:29 +0000 |
|---|---|---|
| committer | Andrew Stitcher <astitcher@apache.org> | 2007-08-31 18:20:29 +0000 |
| commit | 655b3b5806bafdd784f6a9c242e26341bd6aeccc (patch) | |
| tree | 01fe5108d9901b6c577a5930be6ca31a625300fd /cpp/src/qpid/framing/StructHelper.h | |
| parent | f5a1cf995f4956ec2dd83a60715b31ad065f7751 (diff) | |
| download | qpid-python-655b3b5806bafdd784f6a9c242e26341bd6aeccc.tar.gz | |
* Changes to make C++ client code use the asynchronous network IO
* Fixed up the test for buffer changes
* Removed unused buffer operations
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@571529 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/framing/StructHelper.h')
| -rw-r--r-- | cpp/src/qpid/framing/StructHelper.h | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/cpp/src/qpid/framing/StructHelper.h b/cpp/src/qpid/framing/StructHelper.h index dc23a30d58..753a593523 100644 --- a/cpp/src/qpid/framing/StructHelper.h +++ b/cpp/src/qpid/framing/StructHelper.h @@ -24,6 +24,8 @@ #include "qpid/Exception.h" #include "Buffer.h" +#include <stdlib.h> // For alloca + namespace qpid { namespace framing { @@ -33,20 +35,24 @@ public: template <class T> void encode(const T t, std::string& data) { uint32_t size = t.size() + 2/*type*/; - Buffer buffer(size); - buffer.putShort(T::TYPE); - t.encode(buffer); - buffer.flip(); - buffer.getRawData(data, size); + char* bytes = static_cast<char*>(::alloca(size)); + Buffer wbuffer(bytes, size); + wbuffer.putShort(T::TYPE); + t.encode(wbuffer); + + Buffer rbuffer(bytes, size); + rbuffer.getRawData(data, size); } template <class T> void decode(T t, std::string& data) { - Buffer buffer(data.length()); - buffer.putRawData(data); - buffer.flip(); - uint16_t type = buffer.getShort(); + char* bytes = static_cast<char*>(::alloca(data.length())); + Buffer wbuffer(bytes, data.length()); + wbuffer.putRawData(data); + + Buffer rbuffer(bytes, data.length()); + uint16_t type = rbuffer.getShort(); if (type == T::TYPE) { - t.decode(buffer); + t.decode(rbuffer); } else { throw Exception("Type code does not match"); } |
