code gen flexbuffer verifier (#7207)

* code gen flexbuffer verifier

* remove verify nested flexbuffers from flexbuffers

* made function static, and placed higher in file

* moved function to own header
This commit is contained in:
Derek Bailey
2022-04-05 16:29:42 -07:00
committed by GitHub
parent bf17df346e
commit f083b33f2a
10 changed files with 54 additions and 19 deletions

View File

@@ -156,6 +156,7 @@ inline uint64_t ReadUInt64(const uint8_t *data, uint8_t byte_width) {
// TODO: GCC apparently replaces memcpy by a rep movsb, but only if count is a
// constant, which here it isn't. Test if memcpy is still faster than
// the conditionals in ReadSizedScalar. Can also use inline asm.
// clang-format off
#if defined(_MSC_VER) && defined(_M_X64) && !defined(_M_ARM64EC)
// This is 64-bit Windows only, __movsb does not work on 32-bit Windows.
@@ -578,7 +579,7 @@ class Reference {
// unquoted if it looks like an "identifier":
const char *p = keys[i].AsKey();
if (!flatbuffers::is_alpha(*p) && *p != '_') {
kq = true;
kq = true;
} else {
while (*++p) {
if (!flatbuffers::is_alnum(*p) && *p != '_') {
@@ -1422,10 +1423,12 @@ class Builder FLATBUFFERS_FINAL_CLASS {
template<typename T> static Type GetScalarType() {
static_assert(flatbuffers::is_scalar<T>::value, "Unrelated types");
return flatbuffers::is_floating_point<T>::value ? FBT_FLOAT
: flatbuffers::is_same<T, bool>::value
? FBT_BOOL
: (flatbuffers::is_unsigned<T>::value ? FBT_UINT : FBT_INT);
return flatbuffers::is_floating_point<T>::value
? FBT_FLOAT
: flatbuffers::is_same<T, bool>::value
? FBT_BOOL
: (flatbuffers::is_unsigned<T>::value ? FBT_UINT
: FBT_INT);
}
public:
@@ -1876,18 +1879,6 @@ inline bool VerifyBuffer(const uint8_t *buf, size_t buf_len,
return verifier.VerifyBuffer();
}
#ifdef FLATBUFFERS_H_
// This is a verifier utility function that works together with the
// FlatBuffers verifier, which should only be present if flatbuffer.h
// has been included (which it typically is in generated code).
inline bool VerifyNestedFlexBuffer(const flatbuffers::Vector<uint8_t> *nv,
flatbuffers::Verifier &verifier) {
if (!nv) return true;
return verifier.Check(flexbuffers::VerifyBuffer(
nv->data(), nv->size(), verifier.GetFlexReuseTracker()));
}
#endif
} // namespace flexbuffers
#if defined(_MSC_VER)