summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/framing
diff options
context:
space:
mode:
authorAndrew Stitcher <astitcher@apache.org>2007-08-31 18:20:29 +0000
committerAndrew Stitcher <astitcher@apache.org>2007-08-31 18:20:29 +0000
commit655b3b5806bafdd784f6a9c242e26341bd6aeccc (patch)
tree01fe5108d9901b6c577a5930be6ca31a625300fd /cpp/src/qpid/framing
parentf5a1cf995f4956ec2dd83a60715b31ad065f7751 (diff)
downloadqpid-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')
-rw-r--r--cpp/src/qpid/framing/Buffer.cpp48
-rw-r--r--cpp/src/qpid/framing/Buffer.h12
-rw-r--r--cpp/src/qpid/framing/StructHelper.h26
3 files changed, 46 insertions, 40 deletions
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 <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");
}