Avro C++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
Decoder.hh
Go to the documentation of this file.
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, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef avro_Decoder_hh__
20 #define avro_Decoder_hh__
21 
22 #include "Config.hh"
23 #include <stdint.h>
24 #include <string>
25 #include <vector>
26 
27 #include "ValidSchema.hh"
28 #include "Stream.hh"
29 
30 #include <boost/shared_ptr.hpp>
31 
42 
43 namespace avro {
44 
49 class AVRO_DECL Decoder {
50 public:
51  virtual ~Decoder() { };
55  virtual void init(InputStream& is) = 0;
56 
58  virtual void decodeNull() = 0;
59 
61  virtual bool decodeBool() = 0;
62 
64  virtual int32_t decodeInt() = 0;
65 
67  virtual int64_t decodeLong() = 0;
68 
70  virtual float decodeFloat() = 0;
71 
73  virtual double decodeDouble() = 0;
74 
76  std::string decodeString() {
77  std::string result;
78  decodeString(result);
79  return result;
80  }
81 
85  virtual void decodeString(std::string& value) = 0;
86 
88  virtual void skipString() = 0;
89 
91  std::vector<uint8_t> decodeBytes() {
92  std::vector<uint8_t> result;
93  decodeBytes(result);
94  return result;
95  }
96 
99  virtual void decodeBytes(std::vector<uint8_t>& value) = 0;
100 
102  virtual void skipBytes() = 0;
103 
110  std::vector<uint8_t> decodeFixed(size_t n) {
111  std::vector<uint8_t> result;
112  decodeFixed(n, result);
113  return result;
114  }
115 
122  virtual void decodeFixed(size_t n, std::vector<uint8_t>& value) = 0;
123 
125  virtual void skipFixed(size_t n) = 0;
126 
128  virtual size_t decodeEnum() = 0;
129 
131  virtual size_t arrayStart() = 0;
132 
134  virtual size_t arrayNext() = 0;
135 
140  virtual size_t skipArray() = 0;
141 
143  virtual size_t mapStart() = 0;
144 
146  virtual size_t mapNext() = 0;
147 
152  virtual size_t skipMap() = 0;
153 
155  virtual size_t decodeUnionIndex() = 0;
156 };
157 
161 typedef boost::shared_ptr<Decoder> DecoderPtr;
162 
167 class AVRO_DECL ResolvingDecoder : public Decoder {
168 public:
174  virtual const std::vector<size_t>& fieldOrder() = 0;
175 };
176 
180 typedef boost::shared_ptr<ResolvingDecoder> ResolvingDecoderPtr;
184 AVRO_DECL DecoderPtr binaryDecoder();
185 
190 AVRO_DECL DecoderPtr validatingDecoder(const ValidSchema& schema,
191  const DecoderPtr& base);
192 
196 AVRO_DECL DecoderPtr jsonDecoder(const ValidSchema& schema);
197 
204 AVRO_DECL ResolvingDecoderPtr resolvingDecoder(const ValidSchema& writer,
205  const ValidSchema& reader, const DecoderPtr& base);
206 
207 
208 } // namespace avro
209 
210 #endif
std::vector< uint8_t > decodeBytes()
Decodes arbitray binary data from the current stream.
Definition: Decoder.hh:91
boost::shared_ptr< Decoder > DecoderPtr
Shared pointer to Decoder.
Definition: Decoder.hh:161
A bunch of templates and specializations for encoding and decoding specific types.
Definition: AvroParse.hh:31
AVRO_DECL ResolvingDecoderPtr resolvingDecoder(const ValidSchema &writer, const ValidSchema &reader, const DecoderPtr &base)
Returns a decoder that decodes avro data from base written according to writerSchema and resolves aga...
ResolvingDecoder is derived from Decoder, with an additional function to obtain the field ordering of...
Definition: Decoder.hh:167
AVRO_DECL DecoderPtr validatingDecoder(const ValidSchema &schema, const DecoderPtr &base)
Returns an decoder that validates sequence of calls to an underlying Decoder against the given schema...
boost::shared_ptr< ResolvingDecoder > ResolvingDecoderPtr
Shared pointer to ResolvingDecoder.
Definition: Decoder.hh:180
AVRO_DECL DecoderPtr jsonDecoder(const ValidSchema &schema)
Returns an decoder that can decode Avro standard for JSON.
std::vector< uint8_t > decodeFixed(size_t n)
Decodes fixed length binary from the current stream.
Definition: Decoder.hh:110
A ValidSchema is basically a non-mutable Schema that has passed some minumum of sanity checks...
Definition: ValidSchema.hh:40
A no-copy input stream.
Definition: Stream.hh:36
AVRO_DECL DecoderPtr binaryDecoder()
Returns an decoder that can decode binary Avro standard.
std::string decodeString()
Decodes a UTF-8 string from the current stream.
Definition: Decoder.hh:76
Decoder is an interface implemented by every decoder capable of decoding Avro data.
Definition: Decoder.hh:49