client-cpp  0.0.1-SNAPSHOT
GenericAvroConverter.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014 CyberVision, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef GENERICSCHEMACONVERTER_HPP_
18 #define GENERICSCHEMACONVERTER_HPP_
19 
20 #include <avro/ValidSchema.hh>
21 #include <boost/cstdint.hpp>
22 #include <boost/smart_ptr/shared_ptr.hpp>
23 
25 
26 namespace kaa {
27 
29 public:
30  typedef avro::ValidSchema Schema;
31 
32  GenericAvroConverter(Schema schema) { schema_.reset(new Schema(schema)); }
33  GenericAvroConverter(boost::shared_ptr<Schema> schema) { schema_ = schema; }
34  ~GenericAvroConverter() { schema_.reset(); }
35 
36  template <typename T>
37  T decodeBinary(const boost::uint8_t *data, size_t data_length) throw (KaaException);
38 
39  template <typename T>
40  void decodeBinary(const boost::uint8_t *data, size_t data_length, T& result) throw (KaaException);
41 
42  template <typename T>
43  T decodeJson(const boost::uint8_t *data, size_t data_length) throw (KaaException);
44 
45  template <typename T>
46  size_t encode(T &value, std::ostream &os) throw (KaaException);
47 
48 private:
49  boost::shared_ptr<Schema> schema_;
50 };
51 
52 } // namespace kaa
53 
54 
55 #endif /* GENERICSCHEMACONVERTER_HPP_ */
size_t encode(T &value, std::ostream &os)
T decodeBinary(const boost::uint8_t *data, size_t data_length)
GenericAvroConverter(boost::shared_ptr< Schema > schema)
T decodeJson(const boost::uint8_t *data, size_t data_length)