/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/amqp_0_10/UnknownType.h

00001 #ifndef QPID_AMQP_0_10_UNKNOWNTYPE_H
00002 #define QPID_AMQP_0_10_UNKNOWNTYPE_H
00003 
00004 /*
00005  *
00006  * Licensed to the Apache Software Foundation (ASF) under one
00007  * or more contributor license agreements.  See the NOTICE file
00008  * distributed with this work for additional information
00009  * regarding copyright ownership.  The ASF licenses this file
00010  * to you under the Apache License, Version 2.0 (the
00011  * "License"); you may not use this file except in compliance
00012  * with the License.  You may obtain a copy of the License at
00013  * 
00014  *   http://www.apache.org/licenses/LICENSE-2.0
00015  * 
00016  * Unless required by applicable law or agreed to in writing,
00017  * software distributed under the License is distributed on an
00018  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00019  * KIND, either express or implied.  See the License for the
00020  * specific language governing permissions and limitations
00021  * under the License.
00022  *
00023  */
00024 #include <vector>
00025 #include <iosfwd>
00026 #include <stdint.h>
00027 
00028 namespace qpid {
00029 namespace amqp_0_10 {
00030 
00032 class UnknownType {
00033   public:
00034     UnknownType(uint8_t code=0);
00035     uint8_t getCode() const { return code; }
00037     int fixed() const;
00039     int variable() const;
00040 
00041     typedef std::vector<char>::const_iterator const_iterator;
00042     const_iterator begin() const { return data.begin(); }
00043     const_iterator end() const { return data.end(); }
00044     size_t size() const { return data.size(); }
00045 
00046     template <class S> void serialize(S& s) { s.split(*this); }
00047     template <class S> void encode(S& s) const;
00048     template <class S> void decode(S& s);
00049 
00050   private:
00051     uint8_t code;
00052     struct Width { int fixed; int variable; };
00053     static Width WidthTable[16];
00054 
00055     std::vector<char> data;
00056 };
00057 
00058 template <class S> void UnknownType::encode(S& s) const {
00059     switch (variable()) {
00060       case 0: break;
00061       case 1: s(uint8_t(data.size())); break;
00062       case 2: s(uint16_t(data.size())); break;
00063       case 4: s(uint32_t(data.size())); break;
00064     }
00065     s(data.begin(), data.end());
00066 }
00067 
00068 template <class S> void UnknownType::decode(S& s) {
00069     uint32_t s8;
00070     uint32_t s16;
00071     uint32_t s32;
00072     switch (variable()) {
00073       case 0: break;
00074       case 1: s(s8); data.resize(s8); break;
00075       case 2: s(s16); data.resize(s16); break;
00076       case 4: s(s32); data.resize(s32); break;
00077     }
00078     s(data.begin(), data.end());
00079 }
00080 
00081 inline uint8_t codeFor(const UnknownType& u) { return u.getCode(); }
00082 
00083 std::ostream& operator<<(std::ostream&, const UnknownType&);
00084 
00085 }} // namespace qpid::amqp_0_10
00086 
00087 #endif  

Generated on Thu Apr 10 11:08:17 2008 for Qpid by  doxygen 1.4.7