From 655b3b5806bafdd784f6a9c242e26341bd6aeccc Mon Sep 17 00:00:00 2001 From: Andrew Stitcher Date: Fri, 31 Aug 2007 18:20:29 +0000 Subject: * 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 --- cpp/src/qpid/framing/StructHelper.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'cpp/src/qpid/framing/StructHelper.h') 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 // For alloca + namespace qpid { namespace framing { @@ -33,20 +35,24 @@ public: template 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(::alloca(size)); + Buffer wbuffer(bytes, size); + wbuffer.putShort(T::TYPE); + t.encode(wbuffer); + + Buffer rbuffer(bytes, size); + rbuffer.getRawData(data, size); } template 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(::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"); } -- cgit v1.2.1