19 #ifndef avro_Validating_hh__
20 #define avro_Validating_hh__
22 #include <boost/noncopyable.hpp>
29 #include "ValidSchema.hh"
38 void setCount(int64_t) {}
40 static bool typeIsExpected(
Type) {
44 static Type nextTypeExpected() {
48 static int nextSizeExpected() {
52 static bool getCurrentRecordName(std::string &name) {
56 static bool getNextFieldName(std::string &name) {
60 void checkTypeExpected(
Type) {}
61 void checkFixedSizeExpected(
int) {}
70 class AVRO_DECL
Validator :
private boost::noncopyable {
74 void setCount(int64_t val);
76 bool typeIsExpected(
Type type)
const {
77 return (expectedTypesFlag_ & typeToFlag(type)) != 0;
80 Type nextTypeExpected()
const {
84 int nextSizeExpected()
const;
86 bool getCurrentRecordName(std::string &name)
const;
87 bool getNextFieldName(std::string &name)
const;
89 void checkTypeExpected(
Type type) {
90 if (!typeIsExpected(type)) {
92 boost::format(
"Type %1% does not match schema %2%")
98 void checkFixedSizeExpected(
int size) {
99 if (nextSizeExpected() != size) {
101 boost::format(
"Wrong size for fixed, got %1%, expected %2%")
102 % size % nextSizeExpected());
108 using flag_t = uint32_t;
110 static flag_t typeToFlag(
Type type) {
111 flag_t flag = (1L << type);
115 void setupOperation(
const NodePtr &node);
117 void setWaitingForCount();
123 bool countingSetup();
124 void countingAdvance();
128 void setupFlag(
Type type);
133 flag_t expectedTypesFlag_;
134 bool compoundStarted_;
135 bool waitingForCount_;
138 struct CompoundType {
139 explicit CompoundType(NodePtr n) : node(std::move(n)), pos(0) {}
144 std::vector<CompoundType> compoundStack_;
145 std::vector<size_t> counters_;