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/Buffer.cpp | 48 ++++++++++++++++++------------------- cpp/src/qpid/framing/Buffer.h | 12 +++++----- cpp/src/qpid/framing/StructHelper.h | 26 ++++++++++++-------- 3 files changed, 46 insertions(+), 40 deletions(-) (limited to 'cpp/src/qpid/framing') diff --git a/cpp/src/qpid/framing/Buffer.cpp b/cpp/src/qpid/framing/Buffer.cpp index 6c6b2661bd..215102807e 100644 --- a/cpp/src/qpid/framing/Buffer.cpp +++ b/cpp/src/qpid/framing/Buffer.cpp @@ -22,9 +22,9 @@ #include "FramingContent.h" #include "FieldTable.h" -qpid::framing::Buffer::Buffer(uint32_t _size) : size(_size), owner(true), position(0), limit(_size){ - data = new char[size]; -} +//qpid::framing::Buffer::Buffer(uint32_t _size) : size(_size), owner(true), position(0), limit(_size){ +// data = new char[size]; +//} qpid::framing::Buffer::Buffer(char* _data, uint32_t _size) : size(_size), owner(false), data(_data), position(0), limit(_size){ } @@ -33,23 +33,23 @@ qpid::framing::Buffer::~Buffer(){ if(owner) delete[] data; } -void qpid::framing::Buffer::flip(){ - limit = position; - position = 0; -} +//void qpid::framing::Buffer::flip(){ +// limit = position; +// position = 0; +//} -void qpid::framing::Buffer::clear(){ - limit = size; - position = 0; -} +//void qpid::framing::Buffer::clear(){ +// limit = size; +// position = 0; +//} -void qpid::framing::Buffer::compact(){ - uint32_t p = limit - position; - //copy p chars from position to 0 - memmove(data, data + position, p); - limit = size; - position = p; -} +//void qpid::framing::Buffer::compact(){ +// uint32_t p = limit - position; +// //copy p chars from position to 0 +// memmove(data, data + position, p); +// limit = size; +// position = p; +//} void qpid::framing::Buffer::record(){ r_position = position; @@ -65,13 +65,13 @@ uint32_t qpid::framing::Buffer::available(){ return limit - position; } -char* qpid::framing::Buffer::start(){ - return data + position; -} +//char* qpid::framing::Buffer::start(){ +// return data + position; +//} -void qpid::framing::Buffer::move(uint32_t bytes){ - position += bytes; -} +//void qpid::framing::Buffer::move(uint32_t bytes){ +// position += bytes; +//} void qpid::framing::Buffer::putOctet(uint8_t i){ data[position++] = i; diff --git a/cpp/src/qpid/framing/Buffer.h b/cpp/src/qpid/framing/Buffer.h index 04acb65e91..d1eb58f14e 100644 --- a/cpp/src/qpid/framing/Buffer.h +++ b/cpp/src/qpid/framing/Buffer.h @@ -41,18 +41,18 @@ class Buffer public: - Buffer(uint32_t size); + //Buffer(uint32_t size); Buffer(char* data, uint32_t size); ~Buffer(); - void flip(); - void clear(); - void compact(); + //void flip(); + //void clear(); + //void compact(); void record(); void restore(); uint32_t available(); - char* start(); - void move(uint32_t bytes); + //char* start(); + //void move(uint32_t bytes); void putOctet(uint8_t i); void putShort(uint16_t i); 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