From 0a6761806f55ad18d65e2c22cd18a08e2ec5a149 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Wed, 7 Nov 2007 20:55:35 +0000 Subject: Fix for QPID-639: c++ now includes sizes for all structs (enabled the same in python & java) git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@592895 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/framing/AMQHeaderBody.cpp | 2 +- cpp/src/qpid/framing/AMQHeaderBody.h | 19 ++++++++++++++++--- cpp/src/qpid/framing/StructHelper.h | 4 ++-- 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'cpp/src/qpid') diff --git a/cpp/src/qpid/framing/AMQHeaderBody.cpp b/cpp/src/qpid/framing/AMQHeaderBody.cpp index 7083709fde..93568f5f46 100644 --- a/cpp/src/qpid/framing/AMQHeaderBody.cpp +++ b/cpp/src/qpid/framing/AMQHeaderBody.cpp @@ -29,7 +29,7 @@ qpid::framing::AMQHeaderBody::~AMQHeaderBody() {} uint32_t qpid::framing::AMQHeaderBody::size() const{ CalculateSize visitor; for_each(properties.begin(), properties.end(), boost::apply_visitor(visitor)); - return visitor.totalSize() + (properties.size() * (2/*type codes*/ + 4/*size*/)); + return visitor.totalSize(); } void qpid::framing::AMQHeaderBody::encode(Buffer& buffer) const { diff --git a/cpp/src/qpid/framing/AMQHeaderBody.h b/cpp/src/qpid/framing/AMQHeaderBody.h index 76bd60559e..9fd99bd2d9 100644 --- a/cpp/src/qpid/framing/AMQHeaderBody.h +++ b/cpp/src/qpid/framing/AMQHeaderBody.h @@ -41,8 +41,13 @@ class AMQHeaderBody : public AMQBody PropertyList properties; + void decode(BasicHeaderProperties s, Buffer& b, uint32_t size) { + s.decode(b, size); + properties.push_back(s); + } + template void decode(T t, Buffer& b, uint32_t size) { - t.decode(b, size); + t.decodeStructBody(b, size); properties.push_back(t); } @@ -52,10 +57,14 @@ class AMQHeaderBody : public AMQBody Encode(Buffer& b) : buffer(b) {} template void operator()(T& t) const { - buffer.putLong(t.size() + 2/*typecode*/); - buffer.putShort(T::TYPE); t.encode(buffer); } + + void operator()(const BasicHeaderProperties& s) const { + buffer.putLong(s.size() + 2/*typecode*/); + buffer.putShort(BasicHeaderProperties::TYPE); + s.encode(buffer); + } }; class CalculateSize : public boost::static_visitor<> { @@ -67,6 +76,10 @@ class AMQHeaderBody : public AMQBody size += t.size(); } + void operator()(const BasicHeaderProperties& s) { + size += s.size() + 2/*typecode*/ + 4/*size field*/; + } + uint32_t totalSize() { return size; } diff --git a/cpp/src/qpid/framing/StructHelper.h b/cpp/src/qpid/framing/StructHelper.h index 7fc1d2e22b..ad6ba89906 100644 --- a/cpp/src/qpid/framing/StructHelper.h +++ b/cpp/src/qpid/framing/StructHelper.h @@ -38,14 +38,14 @@ public: data.resize(size); Buffer wbuffer(const_cast(data.data()), size); wbuffer.putShort(T::TYPE); - t.encode(wbuffer); + t.encodeStructBody(wbuffer); } template void decode(T& t, const std::string& data) { Buffer rbuffer(const_cast(data.data()), data.length()); uint16_t type = rbuffer.getShort(); if (type == T::TYPE) { - t.decode(rbuffer); + t.decodeStructBody(rbuffer); } else { throw Exception("Type code does not match"); } -- cgit v1.2.1