summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/amqp_0_10/Codec.h
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-04-08 19:53:07 +0000
committerAlan Conway <aconway@apache.org>2008-04-08 19:53:07 +0000
commite72e25abd1272c4e9489f7efd5bc02c4ecf0b5cd (patch)
tree2d32b5153aefb4059ec410118ffd80f37d64b6bd /cpp/src/qpid/amqp_0_10/Codec.h
parent43aaed1c309c8c7ff95695109cf49b5b9157f4b6 (diff)
downloadqpid-python-e72e25abd1272c4e9489f7efd5bc02c4ecf0b5cd.tar.gz
Summary: added 0-10 Array encoding and decoding.
rubygen/0-10/allsegmenttypes.rb: test header,body and each command and control type. rubygen/0-10/specification.rb: enable packed encoding. src/qpid/amqp_0_10/Array.h: Implemented array and array domains. src/qpid/amqp_0_10/Codec.h: enable litte-endian encoding for pack bits src/qpid/amqp_0_10/Packer.h: use litte-endian encoding for pack bits src/qpid/amqp_0_10/Unit.cpp, .h: setting flags, fix op <<. src/qpid/amqp_0_10/complex_types.cpp, .h: added op << src/qpid/framing/Blob.h: copy-object template constructor. src/tests/amqp_0_10/serialize.cpp: - test Array Minor adjustments for new Array.h: src/qpid/amqp_0_10/Map.cpp src/qpid/amqp_0_10/Map.h src/qpid/amqp_0_10/UnknownType.h src/qpid/amqp_0_10/built_in_types.h src/qpid/amqp_0_10/Body.h git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@646054 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/amqp_0_10/Codec.h')
-rw-r--r--cpp/src/qpid/amqp_0_10/Codec.h61
1 files changed, 38 insertions, 23 deletions
diff --git a/cpp/src/qpid/amqp_0_10/Codec.h b/cpp/src/qpid/amqp_0_10/Codec.h
index c4909e7cbd..5cad5cf4ed 100644
--- a/cpp/src/qpid/amqp_0_10/Codec.h
+++ b/cpp/src/qpid/amqp_0_10/Codec.h
@@ -34,13 +34,17 @@
namespace qpid {
namespace amqp_0_10 {
-#ifdef BOOST_LITTLE_ENDIAN
-template <class T> void endianize(T& t) {
+template <class T> void reverse(T& t) {
char*p =reinterpret_cast<char*>(&t);
std::reverse(p, p+sizeof(T));
}
+
+#ifdef BOOST_LITTLE_ENDIAN
+template <class T> void bigEndian(T& t) { reverse(t); }
+template <class T> void littleEndian(T&) {}
#else
-template <class T> void endianize(T&) {}
+template <class T> void littleEndian(T& t) { reverse(t); }
+template <class T> void bigEndian(T&) {}
#endif
/**
@@ -66,16 +70,16 @@ struct Codec {
Encoder& operator()(int8_t x) { raw(x); return *this; }
Encoder& operator()(uint8_t x) { raw(x); return *this; }
- Encoder& operator()(int16_t x) { return endian(x); }
- Encoder& operator()(int32_t x) { return endian(x); }
- Encoder& operator()(int64_t x) { return endian(x); }
+ Encoder& operator()(int16_t x) { return networkByteOrder(x); }
+ Encoder& operator()(int32_t x) { return networkByteOrder(x); }
+ Encoder& operator()(int64_t x) { return networkByteOrder(x); }
- Encoder& operator()(uint16_t x) { return endian(x); }
- Encoder& operator()(uint32_t x) { return endian(x); }
- Encoder& operator()(uint64_t x) { return endian(x); }
+ Encoder& operator()(uint16_t x) { return networkByteOrder(x); }
+ Encoder& operator()(uint32_t x) { return networkByteOrder(x); }
+ Encoder& operator()(uint64_t x) { return networkByteOrder(x); }
- Encoder& operator()(float x) { return endian(x); }
- Encoder& operator()(double x) { return endian(x); }
+ Encoder& operator()(float x) { return networkByteOrder(x); }
+ Encoder& operator()(double x) { return networkByteOrder(x); }
void raw(const void* p, size_t n) {
this->addBytes(n);
@@ -84,12 +88,16 @@ struct Codec {
void raw(char b) { this->addBytes(1); *out++=b; }
+ template <class T> Encoder& littleEnd(T x) {
+ littleEndian(x); raw(&x, sizeof(x)); return *this;
+ }
+
OutIter pos() const { return out; }
private:
- template <class T> Encoder& endian(T x) {
- endianize(x); raw(&x, sizeof(x)); return *this;
+ template <class T> Encoder& networkByteOrder(T x) {
+ bigEndian(x); raw(&x, sizeof(x)); return *this;
}
OutIter out;
@@ -114,16 +122,16 @@ struct Codec {
Decoder& operator()(int8_t& x) { raw((char&)x); return *this; }
Decoder& operator()(uint8_t& x) { raw((char&)x); return *this; }
- Decoder& operator()(int16_t& x) { return endian(x); }
- Decoder& operator()(int32_t& x) { return endian(x); }
- Decoder& operator()(int64_t& x) { return endian(x); }
+ Decoder& operator()(int16_t& x) { return networkByteOrder(x); }
+ Decoder& operator()(int32_t& x) { return networkByteOrder(x); }
+ Decoder& operator()(int64_t& x) { return networkByteOrder(x); }
- Decoder& operator()(uint16_t& x) { return endian(x); }
- Decoder& operator()(uint32_t& x) { return endian(x); }
- Decoder& operator()(uint64_t& x) { return endian(x); }
+ Decoder& operator()(uint16_t& x) { return networkByteOrder(x); }
+ Decoder& operator()(uint32_t& x) { return networkByteOrder(x); }
+ Decoder& operator()(uint64_t& x) { return networkByteOrder(x); }
- Decoder& operator()(float& x) { return endian(x); }
- Decoder& operator()(double& x) { return endian(x); }
+ Decoder& operator()(float& x) { return networkByteOrder(x); }
+ Decoder& operator()(double& x) { return networkByteOrder(x); }
void raw(void *p, size_t n) {
this->addBytes(n);
@@ -133,12 +141,16 @@ struct Codec {
void raw(char &b) { this->addBytes(1); b=*in++; }
+ template <class T> Decoder& littleEnd(T& x) {
+ raw(&x, sizeof(x)); littleEndian(x); return *this;
+ }
+
InIter pos() const { return in; }
private:
- template <class T> Decoder& endian(T& x) {
- raw(&x, sizeof(x)); endianize(x); return *this;
+ template <class T> Decoder& networkByteOrder(T& x) {
+ raw(&x, sizeof(x)); bigEndian(x); return *this;
}
InIter in;
@@ -177,6 +189,8 @@ struct Codec {
void raw(const void*, size_t n){ size += n; }
+ template <class T> Size& littleEnd(T) { size+= sizeof(T); return *this; }
+
private:
size_t size;
};
@@ -191,6 +205,7 @@ struct Codec {
}
template <class T> static size_t size(const T& x) { return Size()(x); }
+ template <class Iter> static size_t size(const Iter& a, const Iter& z) { return Size()(a,z); }
};
}} // namespace qpid::amqp_0_10