Avro C++

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 * https://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 <cstdint>
24 #include <memory>
25 #include <string>
26 #include <vector>
27
28 #include "Stream.hh"
29 #include "ValidSchema.hh"
30
41
42 namespace avro {
43
48 class AVRO_DECL Decoder {
49 public:
50 virtual ~Decoder() = default;
54 virtual void init(InputStream &is) = 0;
55
57 virtual void decodeNull() = 0;
58
60 virtual bool decodeBool() = 0;
61
63 virtual int32_t decodeInt() = 0;
64
66 virtual int64_t decodeLong() = 0;
67
69 virtual float decodeFloat() = 0;
70
72 virtual double decodeDouble() = 0;
73
75 std::string decodeString() {
76 std::string result;
77 decodeString(result);
78 return result;
79 }
80
84 virtual void decodeString(std::string &value) = 0;
85
87 virtual void skipString() = 0;
88
90 std::vector<uint8_t> decodeBytes() {
91 std::vector<uint8_t> result;
92 decodeBytes(result);
93 return result;
94 }
95
98 virtual void decodeBytes(std::vector<uint8_t> &value) = 0;
99
101 virtual void skipBytes() = 0;
102
109 std::vector<uint8_t> decodeFixed(size_t n) {
110 std::vector<uint8_t> result;
111 decodeFixed(n, result);
112 return result;
113 }
114
121 virtual void decodeFixed(size_t n, std::vector<uint8_t> &value) = 0;
122
124 virtual void skipFixed(size_t n) = 0;
125
127 virtual size_t decodeEnum() = 0;
128
130 virtual size_t arrayStart() = 0;
131
133 virtual size_t arrayNext() = 0;
134
139 virtual size_t skipArray() = 0;
140
142 virtual size_t mapStart() = 0;
143
145 virtual size_t mapNext() = 0;
146
151 virtual size_t skipMap() = 0;
152
154 virtual size_t decodeUnionIndex() = 0;
155
171 virtual void drain() = 0;
172 };
173
177 using DecoderPtr = std::shared_ptr<Decoder>;
178
183 class AVRO_DECL ResolvingDecoder : public Decoder {
184 public:
190 virtual const std::vector<size_t> &fieldOrder() = 0;
191 };
192
196 using ResolvingDecoderPtr = std::shared_ptr<ResolvingDecoder>;
200 AVRO_DECL DecoderPtr binaryDecoder();
201
206 AVRO_DECL DecoderPtr validatingDecoder(const ValidSchema &schema,
207 const DecoderPtr &base);
208
212 AVRO_DECL DecoderPtr jsonDecoder(const ValidSchema &schema);
213
220 AVRO_DECL ResolvingDecoderPtr resolvingDecoder(const ValidSchema &writer,
221 const ValidSchema &reader, const DecoderPtr &base);
222
223 } // namespace avro
224
225 #endif
avro::validatingDecoder
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...
avro::Decoder
Decoder is an interface implemented by every decoder capable of decoding Avro data.
Definition: Decoder.hh:48
avro::DecoderPtr
std::shared_ptr< Decoder > DecoderPtr
Shared pointer to Decoder.
Definition: Decoder.hh:177
avro::ResolvingDecoder
ResolvingDecoder is derived from Decoder, with an additional function to obtain the field ordering of...
Definition: Decoder.hh:183
avro::InputStream
A no-copy input stream.
Definition: Stream.hh:36
avro::Decoder::decodeFixed
std::vector< uint8_t > decodeFixed(size_t n)
Decodes fixed length binary from the current stream.
Definition: Decoder.hh:109
avro
A bunch of templates and specializations for encoding and decoding specific types.
Definition: AvroParse.hh:30
avro::ValidSchema
A ValidSchema is basically a non-mutable Schema that has passed some minimum of sanity checks.
Definition: ValidSchema.hh:40
avro::jsonDecoder
AVRO_DECL DecoderPtr jsonDecoder(const ValidSchema &schema)
Returns an decoder that can decode Avro standard for JSON.
avro::resolvingDecoder
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...
avro::binaryDecoder
AVRO_DECL DecoderPtr binaryDecoder()
Returns an decoder that can decode binary Avro standard.
avro::Decoder::decodeString
std::string decodeString()
Decodes a UTF-8 string from the current stream.
Definition: Decoder.hh:75
avro::Decoder::decodeBytes
std::vector< uint8_t > decodeBytes()
Decodes arbitrary binary data from the current stream.
Definition: Decoder.hh:90
avro::ResolvingDecoderPtr
std::shared_ptr< ResolvingDecoder > ResolvingDecoderPtr
Shared pointer to ResolvingDecoder.
Definition: Decoder.hh:196