00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one 00003 * or more contributor license agreements. See the NOTICE file 00004 * distributed with this work for additional information 00005 * regarding copyright ownership. The ASF licenses this file 00006 * to you under the Apache License, Version 2.0 (the 00007 * "License"); you may not use this file except in compliance 00008 * with the License. You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 00019 #ifndef avro_Decoder_hh__ 00020 #define avro_Decoder_hh__ 00021 00022 #include <stdint.h> 00023 #include <string> 00024 #include <vector> 00025 00026 #include "ValidSchema.hh" 00027 #include "Stream.hh" 00028 00029 #include <boost/shared_ptr.hpp> 00030 00041 00042 namespace avro { 00043 00048 class Decoder { 00049 public: 00050 virtual ~Decoder() { }; 00054 virtual void init(InputStream& is) = 0; 00055 00057 virtual void decodeNull() = 0; 00058 00060 virtual bool decodeBool() = 0; 00061 00063 virtual int32_t decodeInt() = 0; 00064 00066 virtual int64_t decodeLong() = 0; 00067 00069 virtual float decodeFloat() = 0; 00070 00072 virtual double decodeDouble() = 0; 00073 00075 std::string decodeString() { 00076 std::string result; 00077 decodeString(result); 00078 return result; 00079 } 00080 00084 virtual void decodeString(std::string& value) = 0; 00085 00087 virtual void skipString() = 0; 00088 00090 std::vector<uint8_t> decodeBytes() { 00091 std::vector<uint8_t> result; 00092 decodeBytes(result); 00093 return result; 00094 } 00095 00098 virtual void decodeBytes(std::vector<uint8_t>& value) = 0; 00099 00101 virtual void skipBytes() = 0; 00102 00109 std::vector<uint8_t> decodeFixed(size_t n) { 00110 std::vector<uint8_t> result; 00111 decodeFixed(n, result); 00112 return result; 00113 } 00114 00121 virtual void decodeFixed(size_t n, std::vector<uint8_t>& value) = 0; 00122 00124 virtual void skipFixed(size_t n) = 0; 00125 00127 virtual size_t decodeEnum() = 0; 00128 00130 virtual size_t arrayStart() = 0; 00131 00133 virtual size_t arrayNext() = 0; 00134 00139 virtual size_t skipArray() = 0; 00140 00142 virtual size_t mapStart() = 0; 00143 00145 virtual size_t mapNext() = 0; 00146 00151 virtual size_t skipMap() = 0; 00152 00154 virtual size_t decodeUnionIndex() = 0; 00155 }; 00156 00160 typedef boost::shared_ptr<Decoder> DecoderPtr; 00161 00166 class ResolvingDecoder : public Decoder { 00167 public: 00173 virtual const std::vector<size_t>& fieldOrder() = 0; 00174 }; 00175 00179 typedef boost::shared_ptr<ResolvingDecoder> ResolvingDecoderPtr; 00183 DecoderPtr binaryDecoder(); 00184 00189 DecoderPtr validatingDecoder(const ValidSchema& schema, 00190 const DecoderPtr& base); 00191 00195 DecoderPtr jsonDecoder(const ValidSchema& schema); 00196 00203 ResolvingDecoderPtr resolvingDecoder(const ValidSchema& writer, 00204 const ValidSchema& reader, const DecoderPtr& base); 00205 00206 00207 } // namespace avro 00208 00209 #endif