}
// Call T::Verify, which must be in the generated code for this type.
- return Verify<uoffset_t>(start) &&
- reinterpret_cast<const T *>(start + ReadScalar<uoffset_t>(start))->
+ auto o = VerifyOffset(start);
+ return o &&
+ reinterpret_cast<const T *>(start + o)->
Verify(*this)
#ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
&& GetComputedSize()
VerifyBufferFromStart<T>(identifier, buf_ + sizeof(uoffset_t));
}
+ uoffset_t VerifyOffset(const uint8_t *start) const {
+ if (!Verify<uoffset_t>(start)) return false;
+ auto o = ReadScalar<uoffset_t>(start);
+ Check(o != 0);
+ return o;
+ }
+
// Called at the start of a table to increase counters measuring data
// structure depth and amount, and possibly bails out with false if
// limits set by the constructor have been hit. Needs to be balanced
// VerifyField for required fields.
template<typename T> bool VerifyFieldRequired(const Verifier &verifier,
- voffset_t field) const {
+ voffset_t field) const {
auto field_offset = GetOptionalFieldOffset(field);
return verifier.Check(field_offset != 0) &&
verifier.Verify<T>(data_ + field_offset);
}
+ // Versions for offsets.
+ bool VerifyOffset(const Verifier &verifier, voffset_t field) const {
+ auto field_offset = GetOptionalFieldOffset(field);
+ return !field_offset || verifier.VerifyOffset(data_ + field_offset);
+ }
+
+ bool VerifyOffsetRequired(const Verifier &verifier, voffset_t field) const {
+ auto field_offset = GetOptionalFieldOffset(field);
+ return verifier.Check(field_offset != 0) &&
+ verifier.VerifyOffset(data_ + field_offset);
+ }
+
private:
// private constructor & copy constructor: you obtain instances of this
// class by pointing to existing data only
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
- VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_KEY) &&
+ VerifyOffsetRequired(verifier, VT_KEY) &&
verifier.Verify(key()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_VALUE) &&
+ VerifyOffset(verifier, VT_VALUE) &&
verifier.Verify(value()) &&
verifier.EndTable();
}
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
- VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_NAME) &&
+ VerifyOffsetRequired(verifier, VT_NAME) &&
verifier.Verify(name()) &&
VerifyField<int64_t>(verifier, VT_VALUE) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_OBJECT) &&
+ VerifyOffset(verifier, VT_OBJECT) &&
verifier.VerifyTable(object()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_UNION_TYPE) &&
+ VerifyOffset(verifier, VT_UNION_TYPE) &&
verifier.VerifyTable(union_type()) &&
verifier.EndTable();
}
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
- VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_NAME) &&
+ VerifyOffsetRequired(verifier, VT_NAME) &&
verifier.Verify(name()) &&
- VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_VALUES) &&
+ VerifyOffsetRequired(verifier, VT_VALUES) &&
verifier.Verify(values()) &&
verifier.VerifyVectorOfTables(values()) &&
VerifyField<uint8_t>(verifier, VT_IS_UNION) &&
- VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_UNDERLYING_TYPE) &&
+ VerifyOffsetRequired(verifier, VT_UNDERLYING_TYPE) &&
verifier.VerifyTable(underlying_type()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_ATTRIBUTES) &&
+ VerifyOffset(verifier, VT_ATTRIBUTES) &&
verifier.Verify(attributes()) &&
verifier.VerifyVectorOfTables(attributes()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_DOCUMENTATION) &&
+ VerifyOffset(verifier, VT_DOCUMENTATION) &&
verifier.Verify(documentation()) &&
verifier.VerifyVectorOfStrings(documentation()) &&
verifier.EndTable();
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
- VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_NAME) &&
+ VerifyOffsetRequired(verifier, VT_NAME) &&
verifier.Verify(name()) &&
- VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_TYPE) &&
+ VerifyOffsetRequired(verifier, VT_TYPE) &&
verifier.VerifyTable(type()) &&
VerifyField<uint16_t>(verifier, VT_ID) &&
VerifyField<uint16_t>(verifier, VT_OFFSET) &&
VerifyField<uint8_t>(verifier, VT_DEPRECATED) &&
VerifyField<uint8_t>(verifier, VT_REQUIRED) &&
VerifyField<uint8_t>(verifier, VT_KEY) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_ATTRIBUTES) &&
+ VerifyOffset(verifier, VT_ATTRIBUTES) &&
verifier.Verify(attributes()) &&
verifier.VerifyVectorOfTables(attributes()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_DOCUMENTATION) &&
+ VerifyOffset(verifier, VT_DOCUMENTATION) &&
verifier.Verify(documentation()) &&
verifier.VerifyVectorOfStrings(documentation()) &&
verifier.EndTable();
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
- VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_NAME) &&
+ VerifyOffsetRequired(verifier, VT_NAME) &&
verifier.Verify(name()) &&
- VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_FIELDS) &&
+ VerifyOffsetRequired(verifier, VT_FIELDS) &&
verifier.Verify(fields()) &&
verifier.VerifyVectorOfTables(fields()) &&
VerifyField<uint8_t>(verifier, VT_IS_STRUCT) &&
VerifyField<int32_t>(verifier, VT_MINALIGN) &&
VerifyField<int32_t>(verifier, VT_BYTESIZE) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_ATTRIBUTES) &&
+ VerifyOffset(verifier, VT_ATTRIBUTES) &&
verifier.Verify(attributes()) &&
verifier.VerifyVectorOfTables(attributes()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_DOCUMENTATION) &&
+ VerifyOffset(verifier, VT_DOCUMENTATION) &&
verifier.Verify(documentation()) &&
verifier.VerifyVectorOfStrings(documentation()) &&
verifier.EndTable();
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
- VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_OBJECTS) &&
+ VerifyOffsetRequired(verifier, VT_OBJECTS) &&
verifier.Verify(objects()) &&
verifier.VerifyVectorOfTables(objects()) &&
- VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_ENUMS) &&
+ VerifyOffsetRequired(verifier, VT_ENUMS) &&
verifier.Verify(enums()) &&
verifier.VerifyVectorOfTables(enums()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_FILE_IDENT) &&
+ VerifyOffset(verifier, VT_FILE_IDENT) &&
verifier.Verify(file_ident()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_FILE_EXT) &&
+ VerifyOffset(verifier, VT_FILE_EXT) &&
verifier.Verify(file_ext()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_ROOT_TABLE) &&
+ VerifyOffset(verifier, VT_ROOT_TABLE) &&
verifier.VerifyTable(root_table()) &&
verifier.EndTable();
}
VerifyField<Vec3>(verifier, VT_POS) &&
VerifyField<int16_t>(verifier, VT_MANA) &&
VerifyField<int16_t>(verifier, VT_HP) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_NAME) &&
+ VerifyOffset(verifier, VT_NAME) &&
verifier.Verify(name()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_INVENTORY) &&
+ VerifyOffset(verifier, VT_INVENTORY) &&
verifier.Verify(inventory()) &&
VerifyField<int8_t>(verifier, VT_COLOR) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_WEAPONS) &&
+ VerifyOffset(verifier, VT_WEAPONS) &&
verifier.Verify(weapons()) &&
verifier.VerifyVectorOfTables(weapons()) &&
VerifyField<uint8_t>(verifier, VT_EQUIPPED_TYPE) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_EQUIPPED) &&
+ VerifyOffset(verifier, VT_EQUIPPED) &&
VerifyEquipment(verifier, equipped(), equipped_type()) &&
verifier.EndTable();
}
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_NAME) &&
+ VerifyOffset(verifier, VT_NAME) &&
verifier.Verify(name()) &&
VerifyField<int16_t>(verifier, VT_DAMAGE) &&
verifier.EndTable();
code_.SetValue("REQUIRED", field.required ? "Required" : "");
code_.SetValue("SIZE", GenTypeSize(field.value.type));
code_.SetValue("OFFSET", GenFieldOffsetName(field));
- code_ += "{{PRE}}VerifyField{{REQUIRED}}<{{SIZE}}>(verifier, {{OFFSET}})\\";
+ if (IsScalar(field.value.type.base_type) || IsStruct(field.value.type)) {
+ code_ +=
+ "{{PRE}}VerifyField{{REQUIRED}}<{{SIZE}}>(verifier, {{OFFSET}})\\";
+ } else {
+ code_ += "{{PRE}}VerifyOffset{{REQUIRED}}(verifier, {{OFFSET}})\\";
+ }
switch (field.value.type.base_type) {
case BASE_TYPE_UNION: {
code += "_fbb.CreateVectorOfNativeStructs<";
code += WrapInNameSpace(*vector_type.struct_def) + ">";
} else {
- code += "_fbb.CreateVectorOfStructs";
+ code += "_fbb.CreateVectorOfStructs";
}
code += "(" + value + ")";
} else {
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_ID) &&
+ VerifyOffset(verifier, VT_ID) &&
verifier.Verify(id()) &&
VerifyField<int64_t>(verifier, VT_VAL) &&
VerifyField<uint16_t>(verifier, VT_COUNT) &&
VerifyField<Vec3>(verifier, VT_POS) &&
VerifyField<int16_t>(verifier, VT_MANA) &&
VerifyField<int16_t>(verifier, VT_HP) &&
- VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_NAME) &&
+ VerifyOffsetRequired(verifier, VT_NAME) &&
verifier.Verify(name()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_INVENTORY) &&
+ VerifyOffset(verifier, VT_INVENTORY) &&
verifier.Verify(inventory()) &&
VerifyField<int8_t>(verifier, VT_COLOR) &&
VerifyField<uint8_t>(verifier, VT_TEST_TYPE) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_TEST) &&
+ VerifyOffset(verifier, VT_TEST) &&
VerifyAny(verifier, test(), test_type()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_TEST4) &&
+ VerifyOffset(verifier, VT_TEST4) &&
verifier.Verify(test4()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_TESTARRAYOFSTRING) &&
+ VerifyOffset(verifier, VT_TESTARRAYOFSTRING) &&
verifier.Verify(testarrayofstring()) &&
verifier.VerifyVectorOfStrings(testarrayofstring()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_TESTARRAYOFTABLES) &&
+ VerifyOffset(verifier, VT_TESTARRAYOFTABLES) &&
verifier.Verify(testarrayoftables()) &&
verifier.VerifyVectorOfTables(testarrayoftables()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_ENEMY) &&
+ VerifyOffset(verifier, VT_ENEMY) &&
verifier.VerifyTable(enemy()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_TESTNESTEDFLATBUFFER) &&
+ VerifyOffset(verifier, VT_TESTNESTEDFLATBUFFER) &&
verifier.Verify(testnestedflatbuffer()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_TESTEMPTY) &&
+ VerifyOffset(verifier, VT_TESTEMPTY) &&
verifier.VerifyTable(testempty()) &&
VerifyField<uint8_t>(verifier, VT_TESTBOOL) &&
VerifyField<int32_t>(verifier, VT_TESTHASHS32_FNV1) &&
VerifyField<uint32_t>(verifier, VT_TESTHASHU32_FNV1A) &&
VerifyField<int64_t>(verifier, VT_TESTHASHS64_FNV1A) &&
VerifyField<uint64_t>(verifier, VT_TESTHASHU64_FNV1A) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_TESTARRAYOFBOOLS) &&
+ VerifyOffset(verifier, VT_TESTARRAYOFBOOLS) &&
verifier.Verify(testarrayofbools()) &&
VerifyField<float>(verifier, VT_TESTF) &&
VerifyField<float>(verifier, VT_TESTF2) &&
VerifyField<float>(verifier, VT_TESTF3) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_TESTARRAYOFSTRING2) &&
+ VerifyOffset(verifier, VT_TESTARRAYOFSTRING2) &&
verifier.Verify(testarrayofstring2()) &&
verifier.VerifyVectorOfStrings(testarrayofstring2()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_TESTARRAYOFSORTEDSTRUCT) &&
+ VerifyOffset(verifier, VT_TESTARRAYOFSORTEDSTRUCT) &&
verifier.Verify(testarrayofsortedstruct()) &&
verifier.EndTable();
}
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_FOO_TABLE) &&
+ VerifyOffset(verifier, VT_FOO_TABLE) &&
verifier.VerifyTable(foo_table()) &&
VerifyField<int8_t>(verifier, VT_FOO_ENUM) &&
VerifyField<NamespaceA::NamespaceB::StructInNestedNS>(verifier, VT_FOO_STRUCT) &&
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_REFER_TO_A1) &&
+ VerifyOffset(verifier, VT_REFER_TO_A1) &&
verifier.VerifyTable(refer_to_a1()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_REFER_TO_A2) &&
+ VerifyOffset(verifier, VT_REFER_TO_A2) &&
verifier.VerifyTable(refer_to_a2()) &&
verifier.EndTable();
}
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_REFER_TO_C) &&
+ VerifyOffset(verifier, VT_REFER_TO_C) &&
verifier.VerifyTable(refer_to_c()) &&
verifier.EndTable();
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<uint8_t>(verifier, VT_MAIN_CHARACTER_TYPE) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_MAIN_CHARACTER) &&
+ VerifyOffset(verifier, VT_MAIN_CHARACTER) &&
VerifyCharacter(verifier, main_character(), main_character_type()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_CHARACTERS_TYPE) &&
+ VerifyOffset(verifier, VT_CHARACTERS_TYPE) &&
verifier.Verify(characters_type()) &&
- VerifyField<flatbuffers::uoffset_t>(verifier, VT_CHARACTERS) &&
+ VerifyOffset(verifier, VT_CHARACTERS) &&
verifier.Verify(characters()) &&
VerifyCharacterVector(verifier, characters(), characters_type()) &&
verifier.EndTable();