Decoder.hh

Go to the documentation of this file.
00001 
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 
00044 class Decoder {
00045 public:
00049     virtual void init(InputStream& is) = 0;
00050 
00052     virtual void decodeNull() = 0;
00053 
00055     virtual bool decodeBool() = 0;
00056 
00058     virtual int32_t decodeInt() = 0;
00059 
00061     virtual int64_t decodeLong() = 0;
00062 
00064     virtual float decodeFloat() = 0;
00065 
00067     virtual double decodeDouble() = 0;
00068 
00070     std::string decodeString() {
00071         std::string result;
00072         decodeString(result);
00073         return result;
00074     }
00075 
00079     virtual void decodeString(std::string& value) = 0;
00080 
00082     virtual void skipString() = 0;
00083 
00085     std::vector<uint8_t> decodeBytes() {
00086         std::vector<uint8_t> result;
00087         decodeBytes(result);
00088         return result;
00089     }
00090 
00093     virtual void decodeBytes(std::vector<uint8_t>& value) = 0;
00094 
00096     virtual void skipBytes() = 0;
00097 
00099     std::vector<uint8_t> decodeFixed(size_t n) {
00100         std::vector<uint8_t> result;
00101         decodeFixed(n, result);
00102         return result;
00103     }
00104 
00105     virtual void decodeFixed(size_t n, std::vector<uint8_t>& value) = 0;
00106 
00108     virtual void skipFixed(size_t n) = 0;
00109 
00111     virtual size_t decodeEnum() = 0;
00112 
00114     virtual size_t arrayStart() = 0;
00115 
00117     virtual size_t arrayNext() = 0;
00118 
00123     virtual size_t skipArray() = 0;
00124 
00126     virtual size_t mapStart() = 0;
00127 
00129     virtual size_t mapNext() = 0;
00130 
00135     virtual size_t skipMap() = 0;
00136 
00138     virtual size_t decodeUnionIndex() = 0;
00139 };
00140 
00141 typedef boost::shared_ptr<Decoder> DecoderPtr;
00142 
00143 class ResolvingDecoder : public Decoder {
00144 public:
00150     virtual const std::vector<size_t>& fieldOrder() = 0;
00151 };
00152 
00153 typedef boost::shared_ptr<ResolvingDecoder> ResolvingDecoderPtr;
00157 DecoderPtr binaryDecoder();
00158 
00163 DecoderPtr validatingDecoder(const ValidSchema& schema,
00164     const DecoderPtr& base);
00165 
00169 DecoderPtr jsonDecoder(const ValidSchema& schema);
00170 
00177 ResolvingDecoderPtr resolvingDecoder(const ValidSchema& writer,
00178     const ValidSchema& reader, const DecoderPtr& base);
00179 
00180 
00181 }   // namespace avro
00182 
00183 #endif