Avro C++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
Parser.hh
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_Parser_hh__
20 #define avro_Parser_hh__
21 
22 #include "Config.hh"
23 #include "Reader.hh"
24 
25 namespace avro {
26 
31 
32 template<class Reader>
33 class Parser : private boost::noncopyable
34 {
35 
36  public:
37 
38  // Constructor only works with Writer
39  explicit Parser(const InputBuffer &in) :
40  reader_(in)
41  {}
42 
44  Parser(const ValidSchema &schema, const InputBuffer &in) :
45  reader_(schema, in)
46  {}
47 
48  void readNull() {
49  Null null;
50  reader_.readValue(null);
51  }
52 
53  bool readBool() {
54  bool val;
55  reader_.readValue(val);
56  return val;
57  }
58 
59  int32_t readInt() {
60  int32_t val;
61  reader_.readValue(val);
62  return val;
63  }
64 
65  int64_t readLong() {
66  int64_t val;
67  reader_.readValue(val);
68  return val;
69  }
70 
71  float readFloat() {
72  float val;
73  reader_.readValue(val);
74  return val;
75  }
76 
77  double readDouble() {
78  double val;
79  reader_.readValue(val);
80  return val;
81  }
82 
83  void readString(std::string &val) {
84  reader_.readValue(val);
85  }
86 
87  void readBytes(std::vector<uint8_t> &val) {
88  reader_.readBytes(val);
89  }
90 
91  template <size_t N>
92  void readFixed(uint8_t (&val)[N]) {
93  reader_.readFixed(val);
94  }
95 
96  template<size_t N>
97  void readFixed(boost::array<uint8_t, N> &val) {
98  reader_.readFixed(val);
99  }
100 
101  void readRecord() {
102  reader_.readRecord();
103  }
104 
105  void readRecordEnd() {
106  reader_.readRecordEnd();
107  }
108 
109  int64_t readArrayBlockSize() {
110  return reader_.readArrayBlockSize();
111  }
112 
113  int64_t readUnion() {
114  return reader_.readUnion();
115  }
116 
117  int64_t readEnum() {
118  return reader_.readEnum();
119  }
120 
121  int64_t readMapBlockSize() {
122  return reader_.readMapBlockSize();
123  }
124 
125  private:
126 
127  friend Type nextType(Parser<ValidatingReader> &p);
128  friend bool currentRecordName(Parser<ValidatingReader> &p, std::string &name);
129  friend bool nextFieldName(Parser<ValidatingReader> &p, std::string &name);
130 
131  Reader reader_;
132 
133 };
134 
135 inline Type nextType(Parser<ValidatingReader> &p) {
136  return p.reader_.nextType();
137 }
138 
139 inline bool currentRecordName(Parser<ValidatingReader> &p, std::string &name) {
140  return p.reader_.currentRecordName(name);
141 }
142 
143 inline bool nextFieldName(Parser<ValidatingReader> &p, std::string &name) {
144  return p.reader_.nextFieldName(name);
145 }
146 
147 } // namespace avro
148 
149 #endif
Type
The "type" for the schema.
Definition: Types.hh:31
A bunch of templates and specializations for encoding and decoding specific types.
Definition: AvroParse.hh:31
Class that wraps a reader or ValidatingReade with an interface that uses explicit get* names instead ...
Definition: Parser.hh:33
define a type to identify Null in template functions
Definition: Types.hh:102
A ValidSchema is basically a non-mutable Schema that has passed some minumum of sanity checks...
Definition: ValidSchema.hh:40
Parser(const ValidSchema &schema, const InputBuffer &in)
Constructor only works with ValidatingWriter.
Definition: Parser.hh:44