Author: aconway
Date: Mon Apr 14 18:58:05 2008
New Revision: 648095

URL: http://svn.apache.org/viewvc?rev=648095&view=rev
Log:
Struct32 encoding

Added:
    incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Header.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.cpp   (with 
props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.h   (with 
props)
Removed:
    incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Frame.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/all_built_in_types.h
Modified:
    incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb
    incubator/qpid/trunk/qpid/cpp/src/Makefile.am
    incubator/qpid/trunk/qpid/cpp/src/qpid/Serializer.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Header.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Holder.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Map.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Map.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Unit.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/built_in_types.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/complex_types.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/complex_types.h
    incubator/qpid/trunk/qpid/cpp/src/tests/amqp_0_10/Map.cpp
    incubator/qpid/trunk/qpid/cpp/src/tests/amqp_0_10/serialize.cpp

Modified: incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb?rev=648095&r1=648094&r2=648095&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb (original)
+++ incubator/qpid/trunk/qpid/cpp/rubygen/0-10/specification.rb Mon Apr 14 
18:58:05 2008
@@ -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 @@
     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 @@
   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 @@
           # 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("[EMAIL PROTECTED]/structs") { 
+      include "[EMAIL PROTECTED]/specification_fwd"
+      include "[EMAIL PROTECTED]/Map.h"
+      include "[EMAIL PROTECTED]/Array.h"
+      include "[EMAIL PROTECTED]/complex_types.h"
+      include "[EMAIL PROTECTED]/UnknownStruct.h"
+      include "[EMAIL PROTECTED]/Packer.h"
+      namespace(@ns) {
+        each_class_ns { |c|
+          c.collect_all(AmqpStruct).each { |s| struct_h s } 
+        }
+      }
+    }
+    
+    cpp_file("[EMAIL PROTECTED]/structs") { 
+      include "[EMAIL PROTECTED]/structs"
+      include "[EMAIL PROTECTED]/Struct32"
+      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_cpp(s) }
         }
       }
     }
@@ -168,23 +188,19 @@
   # Generate the specification files
   def gen_specification()
     h_file("[EMAIL PROTECTED]/specification") {
-      include "[EMAIL PROTECTED]/specification_fwd"
-      include "[EMAIL PROTECTED]/all_built_in_types"
+      include "[EMAIL PROTECTED]/specification_fwd.h"
+      include "[EMAIL PROTECTED]/Map.h"
+      include "[EMAIL PROTECTED]/Array.h"
+      include "[EMAIL PROTECTED]/UnknownType.h"
+      include "[EMAIL PROTECTED]/complex_types.h"
+      include "[EMAIL PROTECTED]/Struct32"
       include "[EMAIL PROTECTED]/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("[EMAIL PROTECTED]/specification") { 
       include "[EMAIL PROTECTED]/specification"
@@ -193,14 +209,13 @@
       ["Command","Control", "Struct"].each { |x| include "[EMAIL 
PROTECTED]/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("[EMAIL PROTECTED]/ProxyTemplate.h") { 
       include "[EMAIL PROTECTED]/specification"
@@ -247,10 +262,14 @@
         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("[EMAIL PROTECTED]/#{base}Visitor.h") { 
-      include "[EMAIL PROTECTED]/specification"
+      include base=="Struct" ? "[EMAIL PROTECTED]/structs" : "[EMAIL 
PROTECTED]/specification"
       namespace("[EMAIL PROTECTED]") { 
         visitor_interface_h(base, subs, false)
         visitor_interface_h(base, subs, true)
@@ -265,12 +284,13 @@
       }
     }
   end
-  
+
   def gen_holder(base, subs)
-    name=base.caps+"Holder"
+    name= (base=="Struct") ? "Struct32" : base+"Holder"
     h_file("[EMAIL PROTECTED]/#{name}") {
       include "[EMAIL PROTECTED]/Apply#{base}"
       include "[EMAIL PROTECTED]/Holder"
+      include base=="Struct" ? "[EMAIL PROTECTED]/structs" : "[EMAIL 
PROTECTED]/specification"
       namespace(@ns){
         namespace("#{base.downcase}_max") {
           gen "template <class M, class X> "
@@ -284,7 +304,7 @@
           }
           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 @@
             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 @@
     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
 

Modified: incubator/qpid/trunk/qpid/cpp/src/Makefile.am
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/Makefile.am?rev=648095&r1=648094&r2=648095&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/Makefile.am Mon Apr 14 18:58:05 2008
@@ -112,6 +112,7 @@
   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 @@
   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 \

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/Serializer.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/Serializer.h?rev=648095&r1=648094&r2=648095&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/Serializer.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/Serializer.h Mon Apr 14 18:58:05 2008
@@ -105,7 +105,7 @@
     /** 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. */

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Header.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Header.cpp?rev=648095&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Header.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Header.cpp Mon Apr 14 
18:58:05 2008
@@ -0,0 +1,34 @@
+/*
+ *
+ * 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 "Header.h"
+
+namespace qpid {
+namespace amqp_0_10 {
+
+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

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Header.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Header.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Header.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Header.h?rev=648095&r1=648094&r2=648095&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Header.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Header.h Mon Apr 14 
18:58:05 2008
@@ -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
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Holder.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Holder.h?rev=648095&r1=648094&r2=648095&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Holder.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Holder.h Mon Apr 14 
18:58:05 2008
@@ -73,6 +73,14 @@
         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;

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Map.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Map.cpp?rev=648095&r1=648094&r2=648095&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Map.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Map.cpp Mon Apr 14 
18:58:05 2008
@@ -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 {

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Map.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Map.h?rev=648095&r1=648094&r2=648095&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Map.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Map.h Mon Apr 14 18:58:05 
2008
@@ -171,7 +171,7 @@
     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));

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Unit.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Unit.cpp?rev=648095&r1=648094&r2=648095&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Unit.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/Unit.cpp Mon Apr 14 
18:58:05 2008
@@ -27,9 +27,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?
     }
 }
 

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.cpp?rev=648095&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.cpp Mon Apr 
14 18:58:05 2008
@@ -0,0 +1,34 @@
+/*
+ *
+ * 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/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 << 
"]";
+}
+
+}} // namespace qpid::amqp_0_10

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.h?rev=648095&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.h Mon Apr 14 
18:58:05 2008
@@ -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*/

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/UnknownStruct.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/built_in_types.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/built_in_types.h?rev=648095&r1=648094&r2=648095&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/built_in_types.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/built_in_types.h Mon Apr 
14 18:58:05 2008
@@ -137,6 +137,7 @@
 
 // Forward declare class types.
 class Map;
+class Struct32;
 class UnknownType;
 template <class T> struct  ArrayDomain;
 typedef ArrayDomain<UnknownType> Array;
@@ -145,13 +146,11 @@
 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 };
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/complex_types.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/complex_types.cpp?rev=648095&r1=648094&r2=648095&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/complex_types.cpp 
(original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/complex_types.cpp Mon Apr 
14 18:58:05 2008
@@ -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 @@
 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;

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/complex_types.h
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/complex_types.h?rev=648095&r1=648094&r2=648095&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/complex_types.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/amqp_0_10/complex_types.h Mon Apr 14 
18:58:05 2008
@@ -93,9 +93,9 @@
 // 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;

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/amqp_0_10/Map.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/amqp_0_10/Map.cpp?rev=648095&r1=648094&r2=648095&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/amqp_0_10/Map.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/amqp_0_10/Map.cpp Mon Apr 14 
18:58:05 2008
@@ -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>
 

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/amqp_0_10/serialize.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/amqp_0_10/serialize.cpp?rev=648095&r1=648094&r2=648095&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/amqp_0_10/serialize.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/amqp_0_10/serialize.cpp Mon Apr 14 
18:58:05 2008
@@ -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_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_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));


Reply via email to