diff options
author | Alan Conway <aconway@apache.org> | 2008-04-15 01:58:05 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2008-04-15 01:58:05 +0000 |
commit | 082266769f09b5e977979da963160eb1fa7fb8b7 (patch) | |
tree | c88cec17464ade1c8f4daa7e11104cf5229354b2 | |
parent | 0671f2b25731d4e3edfb1fd19f5aee1fc2e403f1 (diff) | |
download | qpid-python-082266769f09b5e977979da963160eb1fa7fb8b7.tar.gz |
Struct32 encoding
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@648095 13f79535-47bb-0310-9956-ffa450edef68
-rwxr-xr-x | qpid/cpp/rubygen/0-10/specification.rb | 121 | ||||
-rw-r--r-- | qpid/cpp/src/Makefile.am | 3 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/Serializer.h | 2 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/amqp_0_10/Header.cpp (renamed from qpid/cpp/src/qpid/amqp_0_10/Frame.cpp) | 10 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/amqp_0_10/Header.h | 25 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/amqp_0_10/Holder.h | 8 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/amqp_0_10/Map.cpp | 4 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/amqp_0_10/Map.h | 2 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/amqp_0_10/Unit.cpp | 7 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.cpp (renamed from qpid/cpp/src/qpid/amqp_0_10/all_built_in_types.h) | 21 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.h | 43 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/amqp_0_10/built_in_types.h | 3 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/amqp_0_10/complex_types.cpp | 15 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/amqp_0_10/complex_types.h | 4 | ||||
-rw-r--r-- | qpid/cpp/src/tests/amqp_0_10/Map.cpp | 6 | ||||
-rw-r--r-- | qpid/cpp/src/tests/amqp_0_10/serialize.cpp | 22 |
16 files changed, 215 insertions, 81 deletions
diff --git a/qpid/cpp/rubygen/0-10/specification.rb b/qpid/cpp/rubygen/0-10/specification.rb index 7e73d1c91e..25618116cb 100755 --- a/qpid/cpp/rubygen/0-10/specification.rb +++ b/qpid/cpp/rubygen/0-10/specification.rb @@ -2,6 +2,13 @@ $: << ".." # Include .. in load path require 'cppgen' + +class UnknownStructSub + def visitable?() true end + def fqclassname() "UnknownStruct" end +end + + class Specification < CppGen def initialize(outdir, amqp) super(outdir, amqp) @@ -27,17 +34,6 @@ class Specification < CppGen end end - # class constants - - def class_h(c) - genl "const uint8_t CODE=#{c.code};" - genl "extern const char* NAME;" - end - - def class_cpp(c) - genl "const char* NAME=\"#{c.fqname}\";" - end - def visitable?(x) x.code and x.size=="4" end # Used by structs, commands and controls. @@ -120,7 +116,7 @@ class Specification < CppGen def action_cpp(a) action_struct_cpp(a) { scope("void #{a.classname}::Handler::#{a.funcname}(", ")") { - genl a.unused_parameters.join(",\n") + genl a.unused_parameters.join(",\n") } scope { genl "assert(0);" @@ -146,20 +142,44 @@ class Specification < CppGen # segment-type and track are are built in domain_h d unless ["track","segment-type"].include?(d.name) } - # Domains/structs that must be generated early because they are used by - # other definitions: - @amqp.classes.select{ |c| pregenerate_class?(c) }.each { |c| - namespace(c.nsname) { - c.collect_all(AmqpDomain).each { |d| domain_h d if pregenerate? d } - c.collect_all(AmqpStruct).each { |s| genl "class #{s.classname};" if pregenerate? s } + each_class_ns { |c| + genl "const uint8_t CODE=#{c.code};" # class code + genl "extern const char* NAME;" + c.each_descendant { |x| + case x + when AmqpDomain then domain_h x + when AmqpStruct then genl "class #{x.classname};" + when AmqpAction then genl "class #{x.classname};" + end } } - # Now dependent domains/structs and actions + } + } + end + + # Generate struct definitions into a separate header file so the + # can be included by Struct32.h without circularity. + def gen_structs() + h_file("#{@dir}/structs") { + include "#{@dir}/specification_fwd" + include "#{@dir}/Map.h" + include "#{@dir}/Array.h" + include "#{@dir}/complex_types.h" + include "#{@dir}/UnknownStruct.h" + include "#{@dir}/Packer.h" + namespace(@ns) { each_class_ns { |c| - class_h c - c.collect_all(AmqpDomain).each { |d| domain_h d unless pregenerate? d} - c.collect_all(AmqpStruct).each { |s| genl "class #{s.classname};" unless pregenerate? s } - c.collect_all(AmqpAction).each { |a| genl "class #{a.classname};" unless pregenerate? a } + c.collect_all(AmqpStruct).each { |s| struct_h s } + } + } + } + + cpp_file("#{@dir}/structs") { + include "#{@dir}/structs" + include "#{@dir}/Struct32" + namespace(@ns) { + each_class_ns { |c| + c.collect_all(AmqpStruct).each { |s| struct_cpp(s) } } } } @@ -168,23 +188,19 @@ class Specification < CppGen # Generate the specification files def gen_specification() h_file("#{@dir}/specification") { - include "#{@dir}/specification_fwd" - include "#{@dir}/all_built_in_types" + include "#{@dir}/specification_fwd.h" + include "#{@dir}/Map.h" + include "#{@dir}/Array.h" + include "#{@dir}/UnknownType.h" + include "#{@dir}/complex_types.h" + include "#{@dir}/Struct32" include "#{@dir}/Packer.h" include "<iosfwd>" - namespace(@ns) { - # Structs that must be generated early because - # they are used by other definitions: - each_class_ns { |c| - c.collect_all(AmqpStruct).each { |s| struct_h s if pregenerate? s } - } - # Now dependent domains/structs and actions + namespace(@ns) { each_class_ns { |c| - c.collect_all(AmqpStruct).each { |s| struct_h s unless pregenerate? s} c.collect_all(AmqpAction).each { |a| action_h a } } - } - } + }} cpp_file("#{@dir}/specification") { include "#{@dir}/specification" @@ -193,14 +209,13 @@ class Specification < CppGen ["Command","Control", "Struct"].each { |x| include "#{@dir}/Apply#{x}" } namespace(@ns) { each_class_ns { |c| - class_cpp c + genl "const char* NAME=\"#{c.fqname}\";" c.actions.each { |a| action_cpp a} - c.collect_all(AmqpStruct).each { |s| struct_cpp(s) } } } } end - + def gen_proxy() h_file("#{@dir}/ProxyTemplate.h") { include "#{@dir}/specification" @@ -247,10 +262,14 @@ class Specification < CppGen genl "virtual void visit(#{const}#{s.fqclassname}& x) { this->invoke(x); }" }} end - + def gen_visitor(base, subs) + if base=="Struct" + subs << UnknownStructSub.new + end + h_file("#{@dir}/#{base}Visitor.h") { - include "#{@dir}/specification" + include base=="Struct" ? "#{@dir}/structs" : "#{@dir}/specification" namespace("#{@ns}") { visitor_interface_h(base, subs, false) visitor_interface_h(base, subs, true) @@ -265,12 +284,13 @@ class Specification < CppGen } } end - + def gen_holder(base, subs) - name=base.caps+"Holder" + name= (base=="Struct") ? "Struct32" : base+"Holder" h_file("#{@dir}/#{name}") { include "#{@dir}/Apply#{base}" include "#{@dir}/Holder" + include base=="Struct" ? "#{@dir}/structs" : "#{@dir}/specification" namespace(@ns){ namespace("#{base.downcase}_max") { gen "template <class M, class X> " @@ -284,7 +304,7 @@ class Specification < CppGen } genl "static const int MAX=#{last}::max;" } - holder_base="amqp_0_10::Holder<#{base}Holder, #{base}, #{base.downcase}_max::MAX>" + holder_base="amqp_0_10::Holder<#{name}, #{base}, #{base.downcase}_max::MAX>" struct("#{name}", "public #{holder_base}") { genl "#{name}() {}" genl "template <class T> explicit #{name}(const T& t) : #{holder_base}(t) {}" @@ -308,8 +328,16 @@ class Specification < CppGen subs.each { |s| genl "case 0x#{s.full_code.to_s(16)}: *this=in_place<#{s.fqclassname}>(); break;" } - genl "default: throw CommandInvalidException(QPID_MSG(\"Invalid class-#{base.downcase} key \" << std::hex << key));" - }} + genl "default: " + indent { + if (base=="Struct") + genl "*this=in_place<UnknownStruct>(classCode, code);" + else + genl "throw CommandInvalidException(QPID_MSG(\"Invalid class-#{base.downcase} key \" << std::hex << key));" + end + } + } + } genl genl "std::ostream& operator<<(std::ostream& o, const #{name}& h) { return h.get() ? (o << *h.get()) : (o << \"<empty #{name}>\"); }" } @@ -325,9 +353,10 @@ class Specification < CppGen gen_specification_fwd gen_specification gen_proxy + gen_structs gen_visitable("Command", @amqp.collect_all(AmqpCommand)) gen_visitable("Control", @amqp.collect_all(AmqpControl)) - gen_visitable("Struct", @amqp.collect_all(AmqpStruct).select { |s| s.code}) + gen_visitable("Struct", @amqp.collect_all(AmqpStruct).select { |s| s.code}) end end diff --git a/qpid/cpp/src/Makefile.am b/qpid/cpp/src/Makefile.am index a31dbdfa9d..f2665a5a1f 100644 --- a/qpid/cpp/src/Makefile.am +++ b/qpid/cpp/src/Makefile.am @@ -112,6 +112,7 @@ libqpidcommon_la_SOURCES = \ qpid/amqp_0_10/Array.cpp \ qpid/amqp_0_10/Body.h \ qpid/amqp_0_10/Header.h \ + qpid/amqp_0_10/Header.cpp \ qpid/amqp_0_10/FrameHeader.h \ qpid/amqp_0_10/FrameHeader.cpp \ qpid/amqp_0_10/Holder.h \ @@ -125,6 +126,8 @@ libqpidcommon_la_SOURCES = \ qpid/amqp_0_10/Unit.cpp \ qpid/amqp_0_10/UnknownType.h \ qpid/amqp_0_10/UnknownType.cpp \ + qpid/amqp_0_10/UnknownStruct.h \ + qpid/amqp_0_10/UnknownStruct.cpp \ qpid/Serializer.h \ qpid/framing/AccumulatedAck.cpp \ qpid/framing/AMQBody.cpp \ diff --git a/qpid/cpp/src/qpid/Serializer.h b/qpid/cpp/src/qpid/Serializer.h index fc53097207..a8ded9f5e0 100644 --- a/qpid/cpp/src/qpid/Serializer.h +++ b/qpid/cpp/src/qpid/Serializer.h @@ -105,7 +105,7 @@ template <class Derived> class Serializer { /** Get the max number of bytes that can be processed under the * current limit. */ - size_t getLimit() const { + size_t bytesRemaining() const { return limit - bytes; } /** Set absolute limit. */ diff --git a/qpid/cpp/src/qpid/amqp_0_10/Frame.cpp b/qpid/cpp/src/qpid/amqp_0_10/Header.cpp index 1140b6058d..669c960e7f 100644 --- a/qpid/cpp/src/qpid/amqp_0_10/Frame.cpp +++ b/qpid/cpp/src/qpid/amqp_0_10/Header.cpp @@ -18,11 +18,17 @@ * under the License. * */ -#include "Frame.h" +#include "Header.h" namespace qpid { namespace amqp_0_10 { -bool Frame::match(const Frame& x) { +std::ostream& operator<<(std::ostream& o, const Header& h) { + o << "Header["; + std::ostream_iterator<Struct32> i(o, " "); + std::copy(h.begin(), h.end(), i); + o << "]"; + return o; } + }} // namespace qpid::amqp_0_10 diff --git a/qpid/cpp/src/qpid/amqp_0_10/Header.h b/qpid/cpp/src/qpid/amqp_0_10/Header.h index 44edcb9f3d..b3498a1c8c 100644 --- a/qpid/cpp/src/qpid/amqp_0_10/Header.h +++ b/qpid/cpp/src/qpid/amqp_0_10/Header.h @@ -21,21 +21,32 @@ * under the License. * */ +#include "qpid/amqp_0_10/built_in_types.h" +#include "qpid/amqp_0_10/Struct32.h" +#include <vector> #include <ostream> namespace qpid { namespace amqp_0_10 { -// FIXME aconway 2008-03-27: TODO -class Header -{ +class Header : public std::vector<Struct32> { public: - template <class S> void serialize(S&) {} - private: + Header() {} + + template <class S> void serialize(S& s) { s.split(*this); } + template <class S> void encode(S& s) const { s(this->begin(), this->end()); } + template <class S> void decode(S& s); }; -// FIXME aconway 2008-03-28: TODO -inline std::ostream& operator<<(std::ostream& o, const Header&) { return o; } +template <class S> void Header::decode(S& s) { + this->clear(); + while (s.bytesRemaining() > 0) { + this->push_back(Struct32()); + s(this->back()); + } +} + +std::ostream& operator<<(std::ostream& o, const Header&); }} // namespace qpid::amqp_0_10 diff --git a/qpid/cpp/src/qpid/amqp_0_10/Holder.h b/qpid/cpp/src/qpid/amqp_0_10/Holder.h index 1664afcc8f..3c734d967f 100644 --- a/qpid/cpp/src/qpid/amqp_0_10/Holder.h +++ b/qpid/cpp/src/qpid/amqp_0_10/Holder.h @@ -73,6 +73,14 @@ class Holder : public framing::Blob<Size, BaseHeld> { apply(s, *this->get()); } + template <class T> T* getIf() { + return (getClassCode()==T::CLASS_CODE && getCode()==T::CODE) ? static_cast<T*>(this->get()) : 0; + } + + template <class T> const T* getIf() const { + return (getClassCode()==T::CLASS_CODE && getCode()==T::CODE) ? static_cast<T*>(this->get()) : 0; + } + private: struct Assign : public ApplyFunctor<void> { Holder& holder; diff --git a/qpid/cpp/src/qpid/amqp_0_10/Map.cpp b/qpid/cpp/src/qpid/amqp_0_10/Map.cpp index 2d32466c3f..b517b8baba 100644 --- a/qpid/cpp/src/qpid/amqp_0_10/Map.cpp +++ b/qpid/cpp/src/qpid/amqp_0_10/Map.cpp @@ -18,7 +18,9 @@ * under the License. * */ -#include "all_built_in_types.h" +#include "Map.h" +#include "qpid/amqp_0_10/Struct32.h" +#include "qpid/amqp_0_10/Array.h" #include <ostream> namespace qpid { diff --git a/qpid/cpp/src/qpid/amqp_0_10/Map.h b/qpid/cpp/src/qpid/amqp_0_10/Map.h index d63eb0cc4e..c0dcf73930 100644 --- a/qpid/cpp/src/qpid/amqp_0_10/Map.h +++ b/qpid/cpp/src/qpid/amqp_0_10/Map.h @@ -171,7 +171,7 @@ template <class S> void Map::decode(S& s) { typename S::ScopedLimit l(s, decodedSize); // Make sure we don't overrun. // FIXME aconway 2008-04-03: replace preview with 0-10: // for ( ; count > 0; --count) { - while (s.getLimit() > 0) { + while (s.bytesRemaining() > 0) { key_type k; MapValue v; s(k)(v); insert(value_type(k,v)); diff --git a/qpid/cpp/src/qpid/amqp_0_10/Unit.cpp b/qpid/cpp/src/qpid/amqp_0_10/Unit.cpp index 1fa6b2e085..75ea1c1b30 100644 --- a/qpid/cpp/src/qpid/amqp_0_10/Unit.cpp +++ b/qpid/cpp/src/qpid/amqp_0_10/Unit.cpp @@ -27,9 +27,10 @@ namespace amqp_0_10 { void Unit::updateVariant() { switch (header.getType()) { case CONTROL: variant=ControlHolder(); break; - case COMMAND: variant=CommandHolder(); - case HEADER: variant=Header(); - case BODY: variant=Body(header.getDataSize()); + case COMMAND: variant=CommandHolder(); break; + case HEADER: variant=Header(); break; + case BODY: variant=Body(header.getDataSize()); break; + default: assert(0); // FIXME aconway 2008-04-14: exception? } } diff --git a/qpid/cpp/src/qpid/amqp_0_10/all_built_in_types.h b/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.cpp index 1568465004..023e9d08b4 100644 --- a/qpid/cpp/src/qpid/amqp_0_10/all_built_in_types.h +++ b/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.cpp @@ -1,6 +1,3 @@ -#ifndef QPID_AMQP_0_10_ALL_BUILT_IN_TYPES_H -#define QPID_AMQP_0_10_ALL_BUILT_IN_TYPES_H - /* * * Licensed to the Apache Software Foundation (ASF) under one @@ -22,10 +19,16 @@ * */ -#include "built_in_types.h" -#include "Map.h" -#include "Array.h" -#include "UnknownType.h" -#include "complex_types.h" +#include "qpid/amqp_0_10/StructVisitor.h" +#include "qpid/amqp_0_10/UnknownStruct.h" + +namespace qpid { +namespace amqp_0_10 { + +void UnknownStruct::accept(Visitor& v) { v.visit(*this); } +void UnknownStruct::accept(ConstVisitor& v) const { v.visit(*this); } +std::ostream& operator<<(std::ostream& o, const UnknownStruct& u) { + return o << "UnknownStruct[class=" << u.classCode << " code=" << u.code << "]"; +} -#endif /*!QPID_AMQP_0_10_ALL_BUILT_IN_TYPES_H*/ +}} // namespace qpid::amqp_0_10 diff --git a/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.h b/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.h new file mode 100644 index 0000000000..d4fc77159b --- /dev/null +++ b/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.h @@ -0,0 +1,43 @@ +#ifndef QPID_AMQP_0_10_UNKNOWNSTRUCT_H +#define QPID_AMQP_0_10_UNKNOWNSTRUCT_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include "qpid/amqp_0_10/complex_types.h" + +namespace qpid { +namespace amqp_0_10 { + +struct UnknownStruct : public Struct, public Vbin32 { + static const uint8_t SIZE=4; + static const uint8_t PACK=2; + + UnknownStruct(uint8_t cc=0, uint8_t c=0) : classCode(cc), code(c) {} + void accept(Visitor&); + void accept(ConstVisitor&) const; + uint8_t classCode, code; +}; + +std::ostream& operator<<(std::ostream&, const UnknownStruct&); + +}} // namespace qpid::amqp_0_10 + +#endif /*!QPID_AMQP_0_10_UNKNOWNSTRUCT_H*/ diff --git a/qpid/cpp/src/qpid/amqp_0_10/built_in_types.h b/qpid/cpp/src/qpid/amqp_0_10/built_in_types.h index dccb6a4785..f2ada40bba 100644 --- a/qpid/cpp/src/qpid/amqp_0_10/built_in_types.h +++ b/qpid/cpp/src/qpid/amqp_0_10/built_in_types.h @@ -137,6 +137,7 @@ typedef SerializableString<Uint8, Uint32> Vbin32; // Forward declare class types. class Map; +class Struct32; class UnknownType; template <class T> struct ArrayDomain; typedef ArrayDomain<UnknownType> Array; @@ -145,13 +146,11 @@ typedef ArrayDomain<UnknownType> Array; struct ByteRanges { template <class S> void serialize(S&) {} }; struct SequenceSet { template <class S> void serialize(S&) {} }; struct List { template <class S> void serialize(S&) {} }; -struct Struct32 { template <class S> void serialize(S&) {} }; // FIXME aconway 2008-03-10: dummy ostream operators inline std::ostream& operator<<(std::ostream& o, const ByteRanges&) { return o; } inline std::ostream& operator<<(std::ostream& o, const SequenceSet&) { return o; } inline std::ostream& operator<<(std::ostream& o, const List&) { return o; } -inline std::ostream& operator<<(std::ostream& o, const Struct32&) { return o; } enum SegmentType { CONTROL, COMMAND, HEADER, BODY }; diff --git a/qpid/cpp/src/qpid/amqp_0_10/complex_types.cpp b/qpid/cpp/src/qpid/amqp_0_10/complex_types.cpp index 78ddfeb026..b2975f56d1 100644 --- a/qpid/cpp/src/qpid/amqp_0_10/complex_types.cpp +++ b/qpid/cpp/src/qpid/amqp_0_10/complex_types.cpp @@ -19,6 +19,7 @@ * */ +#include "qpid/amqp_0_10/UnknownStruct.h" #include "qpid/amqp_0_10/ApplyCommand.h" #include "qpid/amqp_0_10/ApplyControl.h" #include "qpid/amqp_0_10/ApplyStruct.h" @@ -52,11 +53,21 @@ uint8_t Control::getClassCode() const { return apply(GetClassCode(), *this); } const char* Control::getName() const { return apply(GetName(), *this); } const char* Control::getClassName() const { return apply(GetClassName(), *this); } +// Special cases for UnknownStruct +struct GetStructCode : public GetCode { + using GetCode::operator(); + uint8_t operator()(const UnknownStruct& u) const { return u.code; } +}; + +struct GetStructClassCode : public GetClassCode { + using GetClassCode::operator(); + uint8_t operator()(const UnknownStruct& u) const { return u.classCode; } +}; -uint8_t Struct::getCode() const { return apply(GetCode(), *this); } +uint8_t Struct::getCode() const { return apply(GetStructCode(), *this); } +uint8_t Struct::getClassCode() const { return apply(GetStructClassCode(), *this); } uint8_t Struct::getPack() const { return apply(GetPack(), *this); } uint8_t Struct::getSize() const { return apply(GetSize(), *this); } -uint8_t Struct::getClassCode() const { return apply(GetClassCode(), *this); } struct PrintVisitor { typedef std::ostream& result_type; diff --git a/qpid/cpp/src/qpid/amqp_0_10/complex_types.h b/qpid/cpp/src/qpid/amqp_0_10/complex_types.h index 5d327cc46e..46d2fa9491 100644 --- a/qpid/cpp/src/qpid/amqp_0_10/complex_types.h +++ b/qpid/cpp/src/qpid/amqp_0_10/complex_types.h @@ -93,9 +93,9 @@ std::ostream& operator<<(std::ostream&, const Control&); // Note: only coded structs inherit from Struct. struct StructVisitor; struct ConstStructVisitor; -struct StructHolder; +struct Struct32; struct Struct - : public Visitable<StructVisitor, ConstStructVisitor, StructHolder> + : public Visitable<StructVisitor, ConstStructVisitor, Struct32> { uint8_t getCode() const; uint8_t getPack() const; diff --git a/qpid/cpp/src/tests/amqp_0_10/Map.cpp b/qpid/cpp/src/tests/amqp_0_10/Map.cpp index dcba6e38c2..dcec1f49f7 100644 --- a/qpid/cpp/src/tests/amqp_0_10/Map.cpp +++ b/qpid/cpp/src/tests/amqp_0_10/Map.cpp @@ -19,8 +19,10 @@ * */ #include "unit_test.h" -#include "qpid/amqp_0_10/all_built_in_types.h" -//FIXME aconway 2008-04-08: #include "qpid/amqp_0_10/allSegmentTypes.h" +#include "qpid/amqp_0_10/Map.h" +#include "qpid/amqp_0_10/Array.h" +#include "qpid/amqp_0_10/Struct32.h" +#include "qpid/amqp_0_10/UnknownType.h" #include "qpid/amqp_0_10/Codec.h" #include <iostream> diff --git a/qpid/cpp/src/tests/amqp_0_10/serialize.cpp b/qpid/cpp/src/tests/amqp_0_10/serialize.cpp index 8928a9fbc9..f38de33bcc 100644 --- a/qpid/cpp/src/tests/amqp_0_10/serialize.cpp +++ b/qpid/cpp/src/tests/amqp_0_10/serialize.cpp @@ -30,7 +30,7 @@ #include "qpid/amqp_0_10/Codec.h" #include "qpid/amqp_0_10/specification.h" #include "qpid/amqp_0_10/ControlHolder.h" -#include "qpid/amqp_0_10/StructHolder.h" +#include "qpid/amqp_0_10/Struct32.h" #include "qpid/amqp_0_10/FrameHeader.h" #include "qpid/amqp_0_10/Map.h" #include "qpid/amqp_0_10/Unit.h" @@ -213,6 +213,22 @@ BOOST_AUTO_TEST_CASE(testControlEncodeDecode) { BOOST_CHECK_EQUAL(tune.heartbeatMax, 4u); } +BOOST_AUTO_TEST_CASE(testStruct32) { + message::DeliveryProperties dp; + dp.priority=message::MEDIUM; + dp.routingKey="foo"; + Struct32 s(dp); + string data; + Codec::encode(back_inserter(data))(s); + BOOST_CHECK_EQUAL(data.size(), Codec::size(s)); + Struct32 s2; + Codec::decode(data.begin())(s2); + message::DeliveryProperties* dp2 = s2.getIf<message::DeliveryProperties>(); + BOOST_REQUIRE(dp2); + BOOST_CHECK_EQUAL(dp2->priority, message::MEDIUM); + BOOST_CHECK_EQUAL(dp2->routingKey, "foo"); +} + struct DummyPacked { static const uint8_t PACK=1; boost::optional<char> i, j; @@ -319,10 +335,10 @@ BOOST_AUTO_TEST_CASE(testStruct) { BOOST_CHECK_EQUAL(encodedBits, packBits(dp)); data.clear(); - Struct::Holder h(dp); + Struct32 h(dp); Codec::encode(back_inserter(data))(h); - Struct::Holder h2; + Struct32 h2; Codec::decode(data.begin())(h2); BOOST_CHECK_EQUAL(h2.getClassCode(), Uint8(message::DeliveryProperties::CLASS_CODE)); BOOST_CHECK_EQUAL(h2.getCode(), Uint8(message::DeliveryProperties::CODE)); |