summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2007-11-07 20:55:35 +0000
committerGordon Sim <gsim@apache.org>2007-11-07 20:55:35 +0000
commit0a6761806f55ad18d65e2c22cd18a08e2ec5a149 (patch)
treee68f5ba20c7096cd1740131d4ab1a9326dfe0053
parentc9900041bf70ac76a4eb8753965fe24426ba8cd4 (diff)
downloadqpid-python-0a6761806f55ad18d65e2c22cd18a08e2ec5a149.tar.gz
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
-rw-r--r--cpp/rubygen/templates/structs.rb61
-rw-r--r--cpp/src/qpid/framing/AMQHeaderBody.cpp2
-rw-r--r--cpp/src/qpid/framing/AMQHeaderBody.h19
-rw-r--r--cpp/src/qpid/framing/StructHelper.h4
-rw-r--r--java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractDecoder.java2
-rw-r--r--java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractEncoder.java2
-rw-r--r--python/qpid/codec.py4
7 files changed, 77 insertions, 17 deletions
diff --git a/cpp/rubygen/templates/structs.rb b/cpp/rubygen/templates/structs.rb
index d67a8925c4..edbadb01f6 100644
--- a/cpp/rubygen/templates/structs.rb
+++ b/cpp/rubygen/templates/structs.rb
@@ -260,7 +260,7 @@ EOS
genl "}"
end
genl "bool #{s.cppname}::has#{f.name.caps}() const { return flags & #{flag_mask(s, i)}; }"
- genl "void #{s.cppname}::clear#{f.name.caps}() { flags &= ~#{flag_mask(s, i)}; }"
+ genl "void #{s.cppname}::clear#{f.name.caps}Flag() { flags &= ~#{flag_mask(s, i)}; }"
end
genl ""
end
@@ -275,9 +275,11 @@ EOS
if (f.cpptype.name == "FieldTable")
genl "#{f.cpptype.name}& get#{f.name.caps}();"
end
- #extra 'accessors' for packed fields:
- genl "bool has#{f.name.caps}() const;";
- genl "void clear#{f.name.caps}();";
+ if (f.domain.type_ != "bit")
+ #extra 'accessors' for packed fields:
+ genl "bool has#{f.name.caps}() const;"
+ genl "void clear#{f.name.caps}Flag();"
+ end
end
def define_accessors(f)
@@ -370,7 +372,10 @@ EOS
gen <<EOS
void encode(Buffer&) const;
void decode(Buffer&, uint32_t=0);
+ void encodeStructBody(Buffer&) const;
+ void decodeStructBody(Buffer&, uint32_t=0);
uint32_t size() const;
+ uint32_t bodySize() const;
void print(std::ostream& out) const;
}; /* class #{classname} */
@@ -394,7 +399,7 @@ EOS
define_packed_accessors(s)
end
gen <<EOS
-void #{classname}::encode(Buffer& #{buffer}) const
+void #{classname}::encodeStructBody(Buffer& #{buffer}) const
{
EOS
if (execution_header?(s))
@@ -409,7 +414,24 @@ EOS
gen <<EOS
}
-void #{classname}::decode(Buffer& #{buffer}, uint32_t /*size*/)
+void #{classname}::encode(Buffer& buffer) const
+{
+EOS
+ indent {
+ if (s.kind_of? AmqpStruct)
+ if (s.type_)
+ genl "buffer.put#{s.size.caps}(bodySize() + 2/*typecode*/);" if s.size
+ genl "buffer.putShort(TYPE);"
+ else
+ genl "buffer.put#{s.size.caps}(size());" if s.size
+ end
+ end
+ genl "encodeStructBody(buffer);"
+ }
+ gen <<EOS
+}
+
+void #{classname}::decodeStructBody(Buffer& #{buffer}, uint32_t /*size*/)
{
EOS
if (execution_header?(s))
@@ -424,7 +446,20 @@ EOS
gen <<EOS
}
-uint32_t #{classname}::size() const
+void #{classname}::decode(Buffer& buffer, uint32_t /*size*/)
+{
+EOS
+ indent {
+ if (s.kind_of? AmqpStruct)
+ genl "buffer.get#{s.size.caps}();" if s.size
+ genl "if (TYPE != buffer.getShort()) throw InternalErrorException(\"Bad type code for struct\");" if s.type_
+ end
+ genl "decodeStructBody(buffer);"
+ }
+ gen <<EOS
+}
+
+uint32_t #{classname}::bodySize() const
{
uint32_t total = 0;
EOS
@@ -441,6 +476,18 @@ EOS
return total;
}
+uint32_t #{classname}::size() const
+{
+ uint32_t total = bodySize();
+EOS
+ if (s.kind_of? AmqpStruct)
+ genl "total += #{SizeMap[s.size]}/*size field*/;" if s.size
+ genl "total += 2/*typecode*/;" if s.type_
+ end
+ gen <<EOS
+ return total;
+}
+
void #{classname}::print(std::ostream& out) const
{
out << "{#{classname}: ";
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 <class T> 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 <class T> 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<char*>(data.data()), size);
wbuffer.putShort(T::TYPE);
- t.encode(wbuffer);
+ t.encodeStructBody(wbuffer);
}
template <class T> void decode(T& t, const std::string& data) {
Buffer rbuffer(const_cast<char*>(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");
}
diff --git a/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractDecoder.java b/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractDecoder.java
index e7c1e9b65a..ae67483a23 100644
--- a/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractDecoder.java
+++ b/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractDecoder.java
@@ -186,7 +186,7 @@ abstract class AbstractDecoder implements Decoder
{
Struct st = Struct.create(type);
int width = st.getSizeWidth();
- if (false && width > 0)
+ if (width > 0)
{
long size = readSize(width);
if (size == 0)
diff --git a/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractEncoder.java b/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractEncoder.java
index 2c16b28e51..c2dd205d66 100644
--- a/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractEncoder.java
+++ b/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractEncoder.java
@@ -223,7 +223,7 @@ abstract class AbstractEncoder implements Encoder
}
int width = s.getSizeWidth();
- if (false && width > 0)
+ if (width > 0)
{
if (empty)
{
diff --git a/python/qpid/codec.py b/python/qpid/codec.py
index 6399ad2a5d..a3663773a9 100644
--- a/python/qpid/codec.py
+++ b/python/qpid/codec.py
@@ -434,7 +434,7 @@ class Codec:
raise ValueError("invalid width: %s" % width)
def encode_struct(self, type, s):
- if False and type.size:
+ if type.size:
enc = StringIO()
codec = Codec(enc, self.spec)
codec.encode_struct_body(type, s)
@@ -446,7 +446,7 @@ class Codec:
self.encode_struct_body(type, s)
def decode_struct(self, type):
- if False and type.size:
+ if type.size:
size = self.dec_num(type.size)
if size == 0:
return None