Author: gsim
Date: Wed Nov 7 12:55:35 2007
New Revision: 592895
URL: http://svn.apache.org/viewvc?rev=592895&view=rev
Log:
Fix for QPID-639: c++ now includes sizes for all structs (enabled the same in
python & java)
Modified:
incubator/qpid/trunk/qpid/cpp/rubygen/templates/structs.rb
incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQHeaderBody.cpp
incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQHeaderBody.h
incubator/qpid/trunk/qpid/cpp/src/qpid/framing/StructHelper.h
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractDecoder.java
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractEncoder.java
incubator/qpid/trunk/qpid/python/qpid/codec.py
Modified: incubator/qpid/trunk/qpid/cpp/rubygen/templates/structs.rb
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/templates/structs.rb?rev=592895&r1=592894&r2=592895&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/templates/structs.rb (original)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/templates/structs.rb Wed Nov 7
12:55:35 2007
@@ -260,7 +260,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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
@@ -437,6 +472,18 @@
else
indent { process_fields(s) { |f, combined| generate_size(f, combined)
} }
end
+ gen <<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;
}
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQHeaderBody.cpp
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQHeaderBody.cpp?rev=592895&r1=592894&r2=592895&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQHeaderBody.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQHeaderBody.cpp Wed Nov 7
12:55:35 2007
@@ -29,7 +29,7 @@
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 {
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQHeaderBody.h
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQHeaderBody.h?rev=592895&r1=592894&r2=592895&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQHeaderBody.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/AMQHeaderBody.h Wed Nov 7
12:55:35 2007
@@ -41,8 +41,13 @@
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 @@
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<> {
@@ -65,6 +74,10 @@
template <class T> void operator()(T& t) {
size += t.size();
+ }
+
+ void operator()(const BasicHeaderProperties& s) {
+ size += s.size() + 2/*typecode*/ + 4/*size field*/;
}
uint32_t totalSize() {
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/StructHelper.h
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/framing/StructHelper.h?rev=592895&r1=592894&r2=592895&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/framing/StructHelper.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/framing/StructHelper.h Wed Nov 7
12:55:35 2007
@@ -38,14 +38,14 @@
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");
}
Modified:
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractDecoder.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractDecoder.java?rev=592895&r1=592894&r2=592895&view=diff
==============================================================================
---
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractDecoder.java
(original)
+++
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractDecoder.java
Wed Nov 7 12:55:35 2007
@@ -186,7 +186,7 @@
{
Struct st = Struct.create(type);
int width = st.getSizeWidth();
- if (false && width > 0)
+ if (width > 0)
{
long size = readSize(width);
if (size == 0)
Modified:
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractEncoder.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractEncoder.java?rev=592895&r1=592894&r2=592895&view=diff
==============================================================================
---
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractEncoder.java
(original)
+++
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/transport/codec/AbstractEncoder.java
Wed Nov 7 12:55:35 2007
@@ -223,7 +223,7 @@
}
int width = s.getSizeWidth();
- if (false && width > 0)
+ if (width > 0)
{
if (empty)
{
Modified: incubator/qpid/trunk/qpid/python/qpid/codec.py
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/codec.py?rev=592895&r1=592894&r2=592895&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/codec.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/codec.py Wed Nov 7 12:55:35 2007
@@ -434,7 +434,7 @@
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 @@
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