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_;