19 #ifndef avro_Reader_hh__
20 #define avro_Reader_hh__
23 #include <boost/noncopyable.hpp>
29 #include "Validator.hh"
31 #include "buffer/BufferReader.hh"
40 template<
class Val
idatorType>
44 explicit ReaderImpl(
const InputBuffer &buffer) : reader_(buffer) {}
49 void readValue(
Null &) {
53 void readValue(
bool &val) {
60 void readValue(int32_t &val) {
61 validator_.checkTypeExpected(
AVRO_INT);
62 auto encoded =
static_cast<uint32_t
>(readVarInt());
63 val = decodeZigzag32(encoded);
66 void readValue(int64_t &val) {
68 uint64_t encoded = readVarInt();
69 val = decodeZigzag64(encoded);
72 void readValue(
float &val) {
82 void readValue(
double &val) {
92 void readValue(std::string &val) {
94 auto size =
static_cast<size_t>(readSize());
95 reader_.read(val, size);
98 void readBytes(std::vector<uint8_t> &val) {
100 auto size =
static_cast<size_t>(readSize());
102 reader_.read(
reinterpret_cast<char *
>(val.data()), size);
105 void readFixed(uint8_t *val,
size_t size) {
106 validator_.checkFixedSizeExpected(size);
107 reader_.read(
reinterpret_cast<char *
>(val), size);
111 void readFixed(uint8_t (&val)[N]) {
112 this->readFixed(val, N);
116 void readFixed(std::array<uint8_t, N> &val) {
117 this->readFixed(val.data(), N);
123 validator_.setCount(1);
126 void readRecordEnd() {
129 validator_.setCount(0);
132 int64_t readArrayBlockSize() {
137 int64_t readUnion() {
147 int64_t readMapBlockSize() {
148 validator_.checkTypeExpected(
AVRO_MAP);
152 Type nextType()
const {
153 return validator_.nextTypeExpected();
156 bool currentRecordName(std::string &name)
const {
157 return validator_.getCurrentRecordName(name);
160 bool nextFieldName(std::string &name)
const {
161 return validator_.getNextFieldName(name);
165 uint64_t readVarInt() {
166 uint64_t encoded = 0;
171 uint64_t newBits =
static_cast<uint64_t
>(val & 0x7f) << shift;
174 }
while (val & 0x80);
180 uint64_t encoded = readVarInt();
181 int64_t size = decodeZigzag64(encoded);
185 int64_t readCount() {
187 int64_t count = readSize();
188 validator_.setCount(count);
192 ValidatorType validator_;
193 BufferReader reader_;
Functions for encoding and decoding integers with zigzag compression.
Parses from an avro encoding to the requested type.
Definition: Reader.hh:41
A ValidSchema is basically a non-mutable Schema that has passed some minimum of sanity checks.
Definition: ValidSchema.hh:40
A bunch of templates and specializations for encoding and decoding specific types.
Definition: AvroParse.hh:30
Type
The "type" for the schema.
Definition: Types.hh:31
@ AVRO_MAP
Definition: Types.hh:45
@ AVRO_FLOAT
Definition: Types.hh:37
@ AVRO_INT
Definition: Types.hh:35
@ AVRO_RECORD
Definition: Types.hh:42
@ AVRO_STRING
Definition: Types.hh:33
@ AVRO_LONG
Definition: Types.hh:36
@ AVRO_DOUBLE
Definition: Types.hh:38
@ AVRO_UNION
Definition: Types.hh:46
@ AVRO_BOOL
Definition: Types.hh:39
@ AVRO_ENUM
Definition: Types.hh:43
@ AVRO_BYTES
Definition: Types.hh:34
@ AVRO_ARRAY
Definition: Types.hh:44
@ AVRO_NULL
Definition: Types.hh:40
define a type to represent Avro Null in template functions
Definition: Types.hh:101