| 30 |
ashish |
1 |
/*
|
|
|
2 |
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
3 |
* or more contributor license agreements. See the NOTICE file
|
|
|
4 |
* distributed with this work for additional information
|
|
|
5 |
* regarding copyright ownership. The ASF licenses this file
|
|
|
6 |
* to you under the Apache License, Version 2.0 (the
|
|
|
7 |
* "License"); you may not use this file except in compliance
|
|
|
8 |
* with the License. You may obtain a copy of the License at
|
|
|
9 |
*
|
|
|
10 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
11 |
*
|
|
|
12 |
* Unless required by applicable law or agreed to in writing,
|
|
|
13 |
* software distributed under the License is distributed on an
|
|
|
14 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
15 |
* KIND, either express or implied. See the License for the
|
|
|
16 |
* specific language governing permissions and limitations
|
|
|
17 |
* under the License.
|
|
|
18 |
*/
|
|
|
19 |
|
|
|
20 |
#ifndef _THRIFT_TEST_GENERICHELPERS_H_
|
|
|
21 |
#define _THRIFT_TEST_GENERICHELPERS_H_ 1
|
|
|
22 |
|
|
|
23 |
#include <protocol/TBinaryProtocol.h>
|
|
|
24 |
#include <transport/TBufferTransports.h>
|
|
|
25 |
#include <Thrift.h>
|
|
|
26 |
|
|
|
27 |
using boost::shared_ptr;
|
|
|
28 |
using namespace apache::thrift::protocol;
|
|
|
29 |
|
|
|
30 |
/* ClassName Helper for cleaner exceptions */
|
|
|
31 |
class ClassNames {
|
|
|
32 |
public:
|
|
|
33 |
template <typename T>
|
|
|
34 |
static const char* getName() { return "Unknown type"; }
|
|
|
35 |
};
|
|
|
36 |
|
|
|
37 |
template <> const char* ClassNames::getName<int8_t>() { return "byte"; }
|
|
|
38 |
template <> const char* ClassNames::getName<int16_t>() { return "short"; }
|
|
|
39 |
template <> const char* ClassNames::getName<int32_t>() { return "int"; }
|
|
|
40 |
template <> const char* ClassNames::getName<int64_t>() { return "long"; }
|
|
|
41 |
template <> const char* ClassNames::getName<double>() { return "double"; }
|
|
|
42 |
template <> const char* ClassNames::getName<std::string>() { return "string"; }
|
|
|
43 |
|
|
|
44 |
/* Generic Protocol I/O function for tests */
|
|
|
45 |
class GenericIO {
|
|
|
46 |
public:
|
|
|
47 |
|
|
|
48 |
/* Write functions */
|
|
|
49 |
|
|
|
50 |
static uint32_t write(shared_ptr<TProtocol> proto, const int8_t& val) {
|
|
|
51 |
return proto->writeByte(val);
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
static uint32_t write(shared_ptr<TProtocol> proto, const int16_t& val) {
|
|
|
55 |
return proto->writeI16(val);
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
static uint32_t write(shared_ptr<TProtocol> proto, const int32_t& val) {
|
|
|
59 |
return proto->writeI32(val);
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
static uint32_t write(shared_ptr<TProtocol> proto, const double& val) {
|
|
|
63 |
return proto->writeDouble(val);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
static uint32_t write(shared_ptr<TProtocol> proto, const int64_t& val) {
|
|
|
67 |
return proto->writeI64(val);
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
static uint32_t write(shared_ptr<TProtocol> proto, const std::string& val) {
|
|
|
71 |
return proto->writeString(val);
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
/* Read functions */
|
|
|
75 |
|
|
|
76 |
static uint32_t read(shared_ptr<TProtocol> proto, int8_t& val) {
|
|
|
77 |
return proto->readByte(val);
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
static uint32_t read(shared_ptr<TProtocol> proto, int16_t& val) {
|
|
|
81 |
return proto->readI16(val);
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
static uint32_t read(shared_ptr<TProtocol> proto, int32_t& val) {
|
|
|
85 |
return proto->readI32(val);
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
static uint32_t read(shared_ptr<TProtocol> proto, int64_t& val) {
|
|
|
89 |
return proto->readI64(val);
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
static uint32_t read(shared_ptr<TProtocol> proto, double& val) {
|
|
|
93 |
return proto->readDouble(val);
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
static uint32_t read(shared_ptr<TProtocol> proto, std::string& val) {
|
|
|
97 |
return proto->readString(val);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
};
|
|
|
101 |
|
|
|
102 |
#endif
|