Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation
StructHelper.h
Go to the documentation of this file.
1 /*
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements. See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership. The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied. See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  */
21 #ifndef _StructHelper_
22 #define _StructHelper_
23 
24 #include "qpid/Exception.h"
26 #include "qpid/framing/Buffer.h"
27 
28 #include <stdlib.h> // For alloca
29 
30 namespace qpid {
31 namespace framing {
32 
34 {
35 public:
36 
37  template <class T> void encode(const T& t, std::string& data) {
38  uint32_t size = t.bodySize() + 2/*type*/;
39  data.resize(size);
40  Buffer wbuffer(const_cast<char*>(data.data()), size);
41  wbuffer.putShort(T::TYPE);
42  t.encodeStructBody(wbuffer);
43  }
44 
45  template <class T> void decode(T& t, const std::string& data) {
46  Buffer rbuffer(const_cast<char*>(data.data()), data.length());
47  uint16_t type = rbuffer.getShort();
48  if (type == T::TYPE) {
49  t.decodeStructBody(rbuffer);
50  } else {
51  throw Exception("Type code does not match");
52  }
53  }
54 };
55 
56 }}
57 #endif
void encode(const T &t, std::string &data)
Definition: StructHelper.h:37
Base class for Qpid runtime exceptions.
Definition: Exception.h:39
unsigned int uint32_t
Definition: IntegerTypes.h:27
unsigned short uint16_t
Definition: IntegerTypes.h:25
This file was automatically generated from the AMQP specification.
Definition: Address.h:27
void putShort(uint16_t i)
void decode(T &t, const std::string &data)
Definition: StructHelper.h:45
#define QPID_COMMON_CLASS_EXTERN

Qpid C++ API Reference
Generated on Fri Feb 6 2015 for Qpid C++ Client API by doxygen 1.8.9.1