aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/flatbuffers/include
diff options
context:
space:
mode:
authorStanislav Kirillov <staskirillov@gmail.com>2022-02-10 16:46:08 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:08 +0300
commitcb68f224c46a8ee52ac3fdd2a32534b8bb8dc134 (patch)
tree1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /contrib/libs/flatbuffers/include
parent92fe2b1e7bc79f7b95adef61714fc003f6ea4a1c (diff)
downloadydb-cb68f224c46a8ee52ac3fdd2a32534b8bb8dc134.tar.gz
Restoring authorship annotation for Stanislav Kirillov <staskirillov@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/flatbuffers/include')
-rw-r--r--contrib/libs/flatbuffers/include/flatbuffers/flatbuffers.h1860
-rw-r--r--contrib/libs/flatbuffers/include/flatbuffers/hash.h182
-rw-r--r--contrib/libs/flatbuffers/include/flatbuffers/idl.h836
-rw-r--r--contrib/libs/flatbuffers/include/flatbuffers/reflection.h710
-rw-r--r--contrib/libs/flatbuffers/include/flatbuffers/reflection_generated.h396
-rw-r--r--contrib/libs/flatbuffers/include/flatbuffers/util.h356
6 files changed, 2170 insertions, 2170 deletions
diff --git a/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers.h b/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers.h
index d33cddadd0..20935307a6 100644
--- a/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers.h
+++ b/contrib/libs/flatbuffers/include/flatbuffers/flatbuffers.h
@@ -1,25 +1,25 @@
-/*
- * Copyright 2014 Google Inc. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef FLATBUFFERS_H_
-#define FLATBUFFERS_H_
-
+/*
+ * Copyright 2014 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FLATBUFFERS_H_
+#define FLATBUFFERS_H_
+
#include "base.h"
#include "stl_emulation.h"
-
+
#ifndef FLATBUFFERS_CPP98_STL
# include <functional>
#endif
@@ -28,7 +28,7 @@
# include <cmath>
#endif
-namespace flatbuffers {
+namespace flatbuffers {
// Generic 'operator==' with conditional specialisations.
// T e - new value of a scalar field.
// T def - default of scalar (is known at compile-time).
@@ -62,135 +62,135 @@ inline bool IsInRange(const T &v, const T &low, const T &high) {
return !IsOutRange(v, low, high);
}
-// Wrapper for uoffset_t to allow safe template specialization.
+// Wrapper for uoffset_t to allow safe template specialization.
// Value is allowed to be 0 to indicate a null object (see e.g. AddOffset).
-template<typename T> struct Offset {
- uoffset_t o;
- Offset() : o(0) {}
- Offset(uoffset_t _o) : o(_o) {}
- Offset<void> Union() const { return Offset<void>(o); }
+template<typename T> struct Offset {
+ uoffset_t o;
+ Offset() : o(0) {}
+ Offset(uoffset_t _o) : o(_o) {}
+ Offset<void> Union() const { return Offset<void>(o); }
bool IsNull() const { return !o; }
-};
-
-inline void EndianCheck() {
- int endiantest = 1;
- // If this fails, see FLATBUFFERS_LITTLEENDIAN above.
+};
+
+inline void EndianCheck() {
+ int endiantest = 1;
+ // If this fails, see FLATBUFFERS_LITTLEENDIAN above.
FLATBUFFERS_ASSERT(*reinterpret_cast<char *>(&endiantest) ==
FLATBUFFERS_LITTLEENDIAN);
- (void)endiantest;
-}
-
+ (void)endiantest;
+}
+
template<typename T> FLATBUFFERS_CONSTEXPR size_t AlignOf() {
// clang-format off
- #ifdef _MSC_VER
- return __alignof(T);
- #else
- #ifndef alignof
- return __alignof__(T);
- #else
- return alignof(T);
- #endif
- #endif
+ #ifdef _MSC_VER
+ return __alignof(T);
+ #else
+ #ifndef alignof
+ return __alignof__(T);
+ #else
+ return alignof(T);
+ #endif
+ #endif
// clang-format on
-}
-
-// When we read serialized data from memory, in the case of most scalars,
-// we want to just read T, but in the case of Offset, we want to actually
-// perform the indirection and return a pointer.
-// The template specialization below does just that.
-// It is wrapped in a struct since function templates can't overload on the
-// return type like this.
-// The typedef is for the convenience of callers of this function
-// (avoiding the need for a trailing return decltype)
-template<typename T> struct IndirectHelper {
- typedef T return_type;
+}
+
+// When we read serialized data from memory, in the case of most scalars,
+// we want to just read T, but in the case of Offset, we want to actually
+// perform the indirection and return a pointer.
+// The template specialization below does just that.
+// It is wrapped in a struct since function templates can't overload on the
+// return type like this.
+// The typedef is for the convenience of callers of this function
+// (avoiding the need for a trailing return decltype)
+template<typename T> struct IndirectHelper {
+ typedef T return_type;
typedef T mutable_return_type;
- static const size_t element_stride = sizeof(T);
- static return_type Read(const uint8_t *p, uoffset_t i) {
- return EndianScalar((reinterpret_cast<const T *>(p))[i]);
- }
-};
-template<typename T> struct IndirectHelper<Offset<T>> {
- typedef const T *return_type;
+ static const size_t element_stride = sizeof(T);
+ static return_type Read(const uint8_t *p, uoffset_t i) {
+ return EndianScalar((reinterpret_cast<const T *>(p))[i]);
+ }
+};
+template<typename T> struct IndirectHelper<Offset<T>> {
+ typedef const T *return_type;
typedef T *mutable_return_type;
- static const size_t element_stride = sizeof(uoffset_t);
- static return_type Read(const uint8_t *p, uoffset_t i) {
- p += i * sizeof(uoffset_t);
- return reinterpret_cast<return_type>(p + ReadScalar<uoffset_t>(p));
- }
-};
-template<typename T> struct IndirectHelper<const T *> {
- typedef const T *return_type;
+ static const size_t element_stride = sizeof(uoffset_t);
+ static return_type Read(const uint8_t *p, uoffset_t i) {
+ p += i * sizeof(uoffset_t);
+ return reinterpret_cast<return_type>(p + ReadScalar<uoffset_t>(p));
+ }
+};
+template<typename T> struct IndirectHelper<const T *> {
+ typedef const T *return_type;
typedef T *mutable_return_type;
- static const size_t element_stride = sizeof(T);
- static return_type Read(const uint8_t *p, uoffset_t i) {
- return reinterpret_cast<const T *>(p + i * sizeof(T));
- }
-};
-
-// An STL compatible iterator implementation for Vector below, effectively
-// calling Get() for every element.
+ static const size_t element_stride = sizeof(T);
+ static return_type Read(const uint8_t *p, uoffset_t i) {
+ return reinterpret_cast<const T *>(p + i * sizeof(T));
+ }
+};
+
+// An STL compatible iterator implementation for Vector below, effectively
+// calling Get() for every element.
template<typename T, typename IT> struct VectorIterator {
typedef std::random_access_iterator_tag iterator_category;
typedef IT value_type;
typedef ptrdiff_t difference_type;
typedef IT *pointer;
typedef IT &reference;
-
+
VectorIterator(const uint8_t *data, uoffset_t i)
: data_(data + IndirectHelper<T>::element_stride * i) {}
- VectorIterator(const VectorIterator &other) : data_(other.data_) {}
+ VectorIterator(const VectorIterator &other) : data_(other.data_) {}
VectorIterator() : data_(nullptr) {}
-
- VectorIterator &operator=(const VectorIterator &other) {
- data_ = other.data_;
- return *this;
- }
-
+
+ VectorIterator &operator=(const VectorIterator &other) {
+ data_ = other.data_;
+ return *this;
+ }
+
// clang-format off
#if !defined(FLATBUFFERS_CPP98_STL)
- VectorIterator &operator=(VectorIterator &&other) {
- data_ = other.data_;
- return *this;
- }
+ VectorIterator &operator=(VectorIterator &&other) {
+ data_ = other.data_;
+ return *this;
+ }
#endif // !defined(FLATBUFFERS_CPP98_STL)
// clang-format on
-
+
bool operator==(const VectorIterator &other) const {
- return data_ == other.data_;
- }
-
+ return data_ == other.data_;
+ }
+
bool operator<(const VectorIterator &other) const {
return data_ < other.data_;
}
bool operator!=(const VectorIterator &other) const {
- return data_ != other.data_;
- }
-
+ return data_ != other.data_;
+ }
+
difference_type operator-(const VectorIterator &other) const {
- return (data_ - other.data_) / IndirectHelper<T>::element_stride;
- }
-
+ return (data_ - other.data_) / IndirectHelper<T>::element_stride;
+ }
+
// Note: return type is incompatible with the standard
// `reference operator*()`.
IT operator*() const { return IndirectHelper<T>::Read(data_, 0); }
-
+
// Note: return type is incompatible with the standard
// `pointer operator->()`.
IT operator->() const { return IndirectHelper<T>::Read(data_, 0); }
-
- VectorIterator &operator++() {
- data_ += IndirectHelper<T>::element_stride;
- return *this;
- }
-
- VectorIterator operator++(int) {
+
+ VectorIterator &operator++() {
+ data_ += IndirectHelper<T>::element_stride;
+ return *this;
+ }
+
+ VectorIterator operator++(int) {
VectorIterator temp(data_, 0);
- data_ += IndirectHelper<T>::element_stride;
- return temp;
- }
-
+ data_ += IndirectHelper<T>::element_stride;
+ return temp;
+ }
+
VectorIterator operator+(const uoffset_t &offset) const {
return VectorIterator(data_ + offset * IndirectHelper<T>::element_stride,
0);
@@ -223,9 +223,9 @@ template<typename T, typename IT> struct VectorIterator {
}
private:
- const uint8_t *data_;
-};
-
+ const uint8_t *data_;
+};
+
template<typename Iterator>
struct VectorReverseIterator : public std::reverse_iterator<Iterator> {
explicit VectorReverseIterator(Iterator iter)
@@ -248,9 +248,9 @@ struct VectorReverseIterator : public std::reverse_iterator<Iterator> {
struct String;
-// This is used as a helper type for accessing vectors.
-// Vector::data() assumes the vector elements start after the length field.
-template<typename T> class Vector {
+// This is used as a helper type for accessing vectors.
+// Vector::data() assumes the vector elements start after the length field.
+template<typename T> class Vector {
public:
typedef VectorIterator<T, typename IndirectHelper<T>::mutable_return_type>
iterator;
@@ -258,31 +258,31 @@ template<typename T> class Vector {
const_iterator;
typedef VectorReverseIterator<iterator> reverse_iterator;
typedef VectorReverseIterator<const_iterator> const_reverse_iterator;
-
- uoffset_t size() const { return EndianScalar(length_); }
-
- // Deprecated: use size(). Here for backwards compatibility.
+
+ uoffset_t size() const { return EndianScalar(length_); }
+
+ // Deprecated: use size(). Here for backwards compatibility.
FLATBUFFERS_ATTRIBUTE(deprecated("use size() instead"))
- uoffset_t Length() const { return size(); }
-
- typedef typename IndirectHelper<T>::return_type return_type;
+ uoffset_t Length() const { return size(); }
+
+ typedef typename IndirectHelper<T>::return_type return_type;
typedef typename IndirectHelper<T>::mutable_return_type mutable_return_type;
typedef return_type value_type;
-
- return_type Get(uoffset_t i) const {
+
+ return_type Get(uoffset_t i) const {
FLATBUFFERS_ASSERT(i < size());
- return IndirectHelper<T>::Read(Data(), i);
- }
-
- return_type operator[](uoffset_t i) const { return Get(i); }
-
- // If this is a Vector of enums, T will be its storage type, not the enum
- // type. This function makes it convenient to retrieve value with enum
- // type E.
- template<typename E> E GetEnum(uoffset_t i) const {
- return static_cast<E>(Get(i));
- }
-
+ return IndirectHelper<T>::Read(Data(), i);
+ }
+
+ return_type operator[](uoffset_t i) const { return Get(i); }
+
+ // If this is a Vector of enums, T will be its storage type, not the enum
+ // type. This function makes it convenient to retrieve value with enum
+ // type E.
+ template<typename E> E GetEnum(uoffset_t i) const {
+ return static_cast<E>(Get(i));
+ }
+
// If this a vector of unions, this does the cast for you. There's no check
// to make sure this is the right type!
template<typename U> const U *GetAs(uoffset_t i) const {
@@ -295,16 +295,16 @@ template<typename T> class Vector {
return reinterpret_cast<const String *>(Get(i));
}
- const void *GetStructFromOffset(size_t o) const {
- return reinterpret_cast<const void *>(Data() + o);
- }
-
- iterator begin() { return iterator(Data(), 0); }
- const_iterator begin() const { return const_iterator(Data(), 0); }
-
- iterator end() { return iterator(Data(), size()); }
- const_iterator end() const { return const_iterator(Data(), size()); }
-
+ const void *GetStructFromOffset(size_t o) const {
+ return reinterpret_cast<const void *>(Data() + o);
+ }
+
+ iterator begin() { return iterator(Data(), 0); }
+ const_iterator begin() const { return const_iterator(Data(), 0); }
+
+ iterator end() { return iterator(Data(), size()); }
+ const_iterator end() const { return const_iterator(Data(), size()); }
+
reverse_iterator rbegin() { return reverse_iterator(end()); }
const_reverse_iterator rbegin() const {
return const_reverse_iterator(end());
@@ -323,98 +323,98 @@ template<typename T> class Vector {
const_reverse_iterator crend() const { return rend(); }
- // Change elements if you have a non-const pointer to this object.
- // Scalars only. See reflection.h, and the documentation.
+ // Change elements if you have a non-const pointer to this object.
+ // Scalars only. See reflection.h, and the documentation.
void Mutate(uoffset_t i, const T &val) {
FLATBUFFERS_ASSERT(i < size());
- WriteScalar(data() + i, val);
- }
-
- // Change an element of a vector of tables (or strings).
- // "val" points to the new table/string, as you can obtain from
- // e.g. reflection::AddFlatBuffer().
- void MutateOffset(uoffset_t i, const uint8_t *val) {
+ WriteScalar(data() + i, val);
+ }
+
+ // Change an element of a vector of tables (or strings).
+ // "val" points to the new table/string, as you can obtain from
+ // e.g. reflection::AddFlatBuffer().
+ void MutateOffset(uoffset_t i, const uint8_t *val) {
FLATBUFFERS_ASSERT(i < size());
static_assert(sizeof(T) == sizeof(uoffset_t), "Unrelated types");
WriteScalar(data() + i,
static_cast<uoffset_t>(val - (Data() + i * sizeof(uoffset_t))));
- }
-
+ }
+
// Get a mutable pointer to tables/strings inside this vector.
mutable_return_type GetMutableObject(uoffset_t i) const {
FLATBUFFERS_ASSERT(i < size());
return const_cast<mutable_return_type>(IndirectHelper<T>::Read(Data(), i));
}
- // The raw data in little endian format. Use with care.
- const uint8_t *Data() const {
- return reinterpret_cast<const uint8_t *>(&length_ + 1);
- }
-
+ // The raw data in little endian format. Use with care.
+ const uint8_t *Data() const {
+ return reinterpret_cast<const uint8_t *>(&length_ + 1);
+ }
+
uint8_t *Data() { return reinterpret_cast<uint8_t *>(&length_ + 1); }
-
- // Similarly, but typed, much like std::vector::data
- const T *data() const { return reinterpret_cast<const T *>(Data()); }
- T *data() { return reinterpret_cast<T *>(Data()); }
-
- template<typename K> return_type LookupByKey(K key) const {
+
+ // Similarly, but typed, much like std::vector::data
+ const T *data() const { return reinterpret_cast<const T *>(Data()); }
+ T *data() { return reinterpret_cast<T *>(Data()); }
+
+ template<typename K> return_type LookupByKey(K key) const {
void *search_result = std::bsearch(
&key, Data(), size(), IndirectHelper<T>::element_stride, KeyCompare<K>);
-
- if (!search_result) {
- return nullptr; // Key not found.
- }
-
- const uint8_t *element = reinterpret_cast<const uint8_t *>(search_result);
-
- return IndirectHelper<T>::Read(element, 0);
- }
-
+
+ if (!search_result) {
+ return nullptr; // Key not found.
+ }
+
+ const uint8_t *element = reinterpret_cast<const uint8_t *>(search_result);
+
+ return IndirectHelper<T>::Read(element, 0);
+ }
+
protected:
- // This class is only used to access pre-existing data. Don't ever
- // try to construct these manually.
- Vector();
-
- uoffset_t length_;
-
+ // This class is only used to access pre-existing data. Don't ever
+ // try to construct these manually.
+ Vector();
+
+ uoffset_t length_;
+
private:
// This class is a pointer. Copying will therefore create an invalid object.
// Private and unimplemented copy constructor.
Vector(const Vector &);
Vector &operator=(const Vector &);
- template<typename K> static int KeyCompare(const void *ap, const void *bp) {
- const K *key = reinterpret_cast<const K *>(ap);
- const uint8_t *data = reinterpret_cast<const uint8_t *>(bp);
- auto table = IndirectHelper<T>::Read(data, 0);
-
- // std::bsearch compares with the operands transposed, so we negate the
- // result here.
- return -table->KeyCompareWithValue(*key);
- }
-};
-
-// Represent a vector much like the template above, but in this case we
-// don't know what the element types are (used with reflection.h).
-class VectorOfAny {
+ template<typename K> static int KeyCompare(const void *ap, const void *bp) {
+ const K *key = reinterpret_cast<const K *>(ap);
+ const uint8_t *data = reinterpret_cast<const uint8_t *>(bp);
+ auto table = IndirectHelper<T>::Read(data, 0);
+
+ // std::bsearch compares with the operands transposed, so we negate the
+ // result here.
+ return -table->KeyCompareWithValue(*key);
+ }
+};
+
+// Represent a vector much like the template above, but in this case we
+// don't know what the element types are (used with reflection.h).
+class VectorOfAny {
public:
- uoffset_t size() const { return EndianScalar(length_); }
-
- const uint8_t *Data() const {
- return reinterpret_cast<const uint8_t *>(&length_ + 1);
- }
+ uoffset_t size() const { return EndianScalar(length_); }
+
+ const uint8_t *Data() const {
+ return reinterpret_cast<const uint8_t *>(&length_ + 1);
+ }
uint8_t *Data() { return reinterpret_cast<uint8_t *>(&length_ + 1); }
protected:
- VectorOfAny();
-
- uoffset_t length_;
+ VectorOfAny();
+
+ uoffset_t length_;
private:
VectorOfAny(const VectorOfAny &);
VectorOfAny &operator=(const VectorOfAny &);
-};
-
+};
+
#ifndef FLATBUFFERS_CPP98_STL
template<typename T, typename U>
Vector<Offset<T>> *VectorCast(Vector<Offset<U>> *ptr) {
@@ -429,12 +429,12 @@ const Vector<Offset<T>> *VectorCast(const Vector<Offset<U>> *ptr) {
}
#endif
-// Convenient helper function to get the length of any vector, regardless
+// Convenient helper function to get the length of any vector, regardless
// of whether it is null or not (the field is not set).
-template<typename T> static inline size_t VectorLength(const Vector<T> *v) {
+template<typename T> static inline size_t VectorLength(const Vector<T> *v) {
return v ? v->size() : 0;
-}
-
+}
+
// This is used as a helper type for accessing arrays.
template<typename T, uint16_t length> class Array {
typedef
@@ -625,10 +625,10 @@ static inline bool StringLessThan(const char *a_data, uoffset_t a_size,
return cmp == 0 ? a_size < b_size : cmp < 0;
}
-struct String : public Vector<char> {
- const char *c_str() const { return reinterpret_cast<const char *>(Data()); }
+struct String : public Vector<char> {
+ const char *c_str() const { return reinterpret_cast<const char *>(Data()); }
std::string str() const { return std::string(c_str(), size()); }
-
+
// clang-format off
#ifdef FLATBUFFERS_HAS_STRING_VIEW
flatbuffers::string_view string_view() const {
@@ -639,9 +639,9 @@ struct String : public Vector<char> {
bool operator<(const String &o) const {
return StringLessThan(this->data(), this->size(), o.data(), o.size());
- }
-};
-
+ }
+};
+
// Convenience function to get std::string from a String returning an empty
// string on null pointer.
static inline std::string GetString(const String *str) {
@@ -665,7 +665,7 @@ static inline flatbuffers::string_view GetStringView(const String *str) {
// Allocator interface. This is flatbuffers-specific and meant only for
// `vector_downward` usage.
class Allocator {
- public:
+ public:
virtual ~Allocator() {}
// Allocate `size` bytes of memory.
@@ -702,8 +702,8 @@ class Allocator {
in_use_back);
memcpy(new_p, old_p, in_use_front);
}
-};
-
+};
+
// DefaultAllocator uses new/delete to allocate memory regions
class DefaultAllocator : public Allocator {
public:
@@ -865,14 +865,14 @@ class DetachedBuffer {
}
};
-// This is a minimal replication of std::vector<uint8_t> functionality,
-// except growing from higher to lower addresses. i.e push_back() inserts data
-// in the lowest address in the vector.
+// This is a minimal replication of std::vector<uint8_t> functionality,
+// except growing from higher to lower addresses. i.e push_back() inserts data
+// in the lowest address in the vector.
// Since this vector leaves the lower part unused, we support a "scratch-pad"
// that can be stored there for temporary data, to share the allocated space.
// Essentially, this supports 2 std::vectors in a single buffer.
-class vector_downward {
- public:
+class vector_downward {
+ public:
explicit vector_downward(size_t initial_size, Allocator *allocator,
bool own_allocator, size_t buffer_minalign)
: allocator_(allocator),
@@ -907,8 +907,8 @@ class vector_downward {
other.buf_ = nullptr;
other.cur_ = nullptr;
other.scratch_ = nullptr;
- }
-
+ }
+
// clang-format off
#if !defined(FLATBUFFERS_CPP98_STL)
// clang-format on
@@ -922,11 +922,11 @@ class vector_downward {
#endif // defined(FLATBUFFERS_CPP98_STL)
// clang-format on
- ~vector_downward() {
+ ~vector_downward() {
clear_buffer();
clear_allocator();
- }
-
+ }
+
void reset() {
clear_buffer();
clear();
@@ -940,8 +940,8 @@ class vector_downward {
cur_ = nullptr;
}
clear_scratch();
- }
-
+ }
+
void clear_scratch() { scratch_ = buf_; }
void clear_allocator() {
@@ -955,7 +955,7 @@ class vector_downward {
buf_ = nullptr;
}
- // Relinquish the pointer to the caller.
+ // Relinquish the pointer to the caller.
uint8_t *release_raw(size_t &allocated_bytes, size_t &offset) {
auto *buf = buf_;
allocated_bytes = reserved_;
@@ -977,11 +977,11 @@ class vector_downward {
allocator_ = nullptr;
own_allocator_ = false;
}
- buf_ = nullptr;
+ buf_ = nullptr;
clear();
return fb;
- }
-
+ }
+
size_t ensure_space(size_t len) {
FLATBUFFERS_ASSERT(cur_ >= scratch_ && scratch_ >= buf_);
if (len > static_cast<size_t>(cur_ - scratch_)) { reallocate(len); }
@@ -989,32 +989,32 @@ class vector_downward {
// (FlatBuffers > 2GB not supported).
FLATBUFFERS_ASSERT(size() < FLATBUFFERS_MAX_BUFFER_SIZE);
return len;
- }
-
+ }
+
inline uint8_t *make_space(size_t len) {
size_t space = ensure_space(len);
cur_ -= space;
- return cur_;
- }
-
+ return cur_;
+ }
+
// Returns nullptr if using the DefaultAllocator.
Allocator *get_custom_allocator() { return allocator_; }
- uoffset_t size() const {
+ uoffset_t size() const {
return static_cast<uoffset_t>(reserved_ - static_cast<size_t>(cur_ - buf_));
- }
-
+ }
+
uoffset_t scratch_size() const {
return static_cast<uoffset_t>(scratch_ - buf_);
}
size_t capacity() const { return reserved_; }
- uint8_t *data() const {
+ uint8_t *data() const {
FLATBUFFERS_ASSERT(cur_);
- return cur_;
- }
-
+ return cur_;
+ }
+
uint8_t *scratch_data() const {
FLATBUFFERS_ASSERT(buf_);
return buf_;
@@ -1026,11 +1026,11 @@ class vector_downward {
}
uint8_t *data_at(size_t offset) const { return buf_ + reserved_ - offset; }
-
- void push(const uint8_t *bytes, size_t num) {
+
+ void push(const uint8_t *bytes, size_t num) {
if (num > 0) { memcpy(make_space(num), bytes, num); }
- }
-
+ }
+
// Specialized version of push() that avoids memcpy call for small data.
template<typename T> void push_small(const T &little_endian_t) {
make_space(sizeof(T));
@@ -1045,20 +1045,20 @@ class vector_downward {
// fill() is most frequently called with small byte counts (<= 4),
// which is why we're using loops rather than calling memset.
- void fill(size_t zero_pad_bytes) {
+ void fill(size_t zero_pad_bytes) {
make_space(zero_pad_bytes);
for (size_t i = 0; i < zero_pad_bytes; i++) cur_[i] = 0;
- }
-
+ }
+
// Version for when we know the size is larger.
// Precondition: zero_pad_bytes > 0
void fill_big(size_t zero_pad_bytes) {
memset(make_space(zero_pad_bytes), 0, zero_pad_bytes);
}
- void pop(size_t bytes_to_remove) { cur_ += bytes_to_remove; }
+ void pop(size_t bytes_to_remove) { cur_ += bytes_to_remove; }
void scratch_pop(size_t bytes_to_remove) { scratch_ -= bytes_to_remove; }
-
+
void swap(vector_downward &other) {
using std::swap;
swap(allocator_, other.allocator_);
@@ -1077,18 +1077,18 @@ class vector_downward {
swap(own_allocator_, other.own_allocator_);
}
- private:
- // You shouldn't really be copying instances of this class.
+ private:
+ // You shouldn't really be copying instances of this class.
FLATBUFFERS_DELETE_FUNC(vector_downward(const vector_downward &));
FLATBUFFERS_DELETE_FUNC(vector_downward &operator=(const vector_downward &));
-
+
Allocator *allocator_;
bool own_allocator_;
size_t initial_size_;
size_t buffer_minalign_;
- size_t reserved_;
- uint8_t *buf_;
- uint8_t *cur_; // Points at location between empty (below) and used (above).
+ size_t reserved_;
+ uint8_t *buf_;
+ uint8_t *cur_; // Points at location between empty (below) and used (above).
uint8_t *scratch_; // Points to the end of the scratchpad in use.
void reallocate(size_t len) {
@@ -1107,22 +1107,22 @@ class vector_downward {
cur_ = buf_ + reserved_ - old_size;
scratch_ = buf_ + old_scratch_size;
}
-};
-
-// Converts a Field ID to a virtual table offset.
-inline voffset_t FieldIndexToOffset(voffset_t field_id) {
- // Should correspond to what EndTable() below builds up.
- const int fixed_fields = 2; // Vtable size and Object Size.
+};
+
+// Converts a Field ID to a virtual table offset.
+inline voffset_t FieldIndexToOffset(voffset_t field_id) {
+ // Should correspond to what EndTable() below builds up.
+ const int fixed_fields = 2; // Vtable size and Object Size.
return static_cast<voffset_t>((field_id + fixed_fields) * sizeof(voffset_t));
-}
-
+}
+
template<typename T, typename Alloc>
const T *data(const std::vector<T, Alloc> &v) {
// Eventually the returned pointer gets passed down to memcpy, so
// we need it to be non-null to avoid undefined behavior.
static uint8_t t;
return v.empty() ? reinterpret_cast<const T *>(&t) : &v.front();
-}
+}
template<typename T, typename Alloc> T *data(std::vector<T, Alloc> &v) {
// Eventually the returned pointer gets passed down to memcpy, so
// we need it to be non-null to avoid undefined behavior.
@@ -1130,21 +1130,21 @@ template<typename T, typename Alloc> T *data(std::vector<T, Alloc> &v) {
return v.empty() ? reinterpret_cast<T *>(&t) : &v.front();
}
-/// @endcond
-
-/// @addtogroup flatbuffers_cpp_api
-/// @{
-/// @class FlatBufferBuilder
-/// @brief Helper class to hold data needed in creation of a FlatBuffer.
-/// To serialize data, you typically call one of the `Create*()` functions in
-/// the generated code, which in turn call a sequence of `StartTable`/
-/// `PushElement`/`AddElement`/`EndTable`, or the builtin `CreateString`/
-/// `CreateVector` functions. Do this is depth-first order to build up a tree to
-/// the root. `Finish()` wraps up the buffer ready for transport.
+/// @endcond
+
+/// @addtogroup flatbuffers_cpp_api
+/// @{
+/// @class FlatBufferBuilder
+/// @brief Helper class to hold data needed in creation of a FlatBuffer.
+/// To serialize data, you typically call one of the `Create*()` functions in
+/// the generated code, which in turn call a sequence of `StartTable`/
+/// `PushElement`/`AddElement`/`EndTable`, or the builtin `CreateString`/
+/// `CreateVector` functions. Do this is depth-first order to build up a tree to
+/// the root. `Finish()` wraps up the buffer ready for transport.
class FlatBufferBuilder {
- public:
- /// @brief Default constructor for FlatBufferBuilder.
- /// @param[in] initial_size The initial size of the buffer, in bytes. Defaults
+ public:
+ /// @brief Default constructor for FlatBufferBuilder.
+ /// @param[in] initial_size The initial size of the buffer, in bytes. Defaults
/// to `1024`.
/// @param[in] allocator An `Allocator` to use. If null will use
/// `DefaultAllocator`.
@@ -1167,9 +1167,9 @@ class FlatBufferBuilder {
force_defaults_(false),
dedup_vtables_(true),
string_pool(nullptr) {
- EndianCheck();
- }
-
+ EndianCheck();
+ }
+
// clang-format off
/// @brief Move constructor for FlatBufferBuilder.
#if !defined(FLATBUFFERS_CPP98_STL)
@@ -1229,29 +1229,29 @@ class FlatBufferBuilder {
buf_.reset(); // deallocate buffer
}
- /// @brief Reset all the state in this FlatBufferBuilder so it can be reused
- /// to construct another buffer.
- void Clear() {
+ /// @brief Reset all the state in this FlatBufferBuilder so it can be reused
+ /// to construct another buffer.
+ void Clear() {
ClearOffsets();
- buf_.clear();
- nested = false;
- finished = false;
- minalign_ = 1;
+ buf_.clear();
+ nested = false;
+ finished = false;
+ minalign_ = 1;
if (string_pool) string_pool->clear();
- }
-
- /// @brief The current size of the serialized buffer, counting from the end.
- /// @return Returns an `uoffset_t` with the current size of the buffer.
- uoffset_t GetSize() const { return buf_.size(); }
-
- /// @brief Get the serialized buffer (after you call `Finish()`).
- /// @return Returns an `uint8_t` pointer to the FlatBuffer data inside the
- /// buffer.
- uint8_t *GetBufferPointer() const {
- Finished();
- return buf_.data();
- }
-
+ }
+
+ /// @brief The current size of the serialized buffer, counting from the end.
+ /// @return Returns an `uoffset_t` with the current size of the buffer.
+ uoffset_t GetSize() const { return buf_.size(); }
+
+ /// @brief Get the serialized buffer (after you call `Finish()`).
+ /// @return Returns an `uint8_t` pointer to the FlatBuffer data inside the
+ /// buffer.
+ uint8_t *GetBufferPointer() const {
+ Finished();
+ return buf_.data();
+ }
+
/// @brief Get the serialized buffer (after you call `Finish()`) as a span.
/// @return Returns a constructed flatbuffers::span that is a view over the
/// FlatBuffer data inside the buffer.
@@ -1260,20 +1260,20 @@ class FlatBufferBuilder {
return flatbuffers::span<uint8_t>(buf_.data(), buf_.size());
}
- /// @brief Get a pointer to an unfinished buffer.
- /// @return Returns a `uint8_t` pointer to the unfinished buffer.
- uint8_t *GetCurrentBufferPointer() const { return buf_.data(); }
-
- /// @brief Get the released pointer to the serialized buffer.
- /// @warning Do NOT attempt to use this FlatBufferBuilder afterwards!
+ /// @brief Get a pointer to an unfinished buffer.
+ /// @return Returns a `uint8_t` pointer to the unfinished buffer.
+ uint8_t *GetCurrentBufferPointer() const { return buf_.data(); }
+
+ /// @brief Get the released pointer to the serialized buffer.
+ /// @warning Do NOT attempt to use this FlatBufferBuilder afterwards!
/// @return A `FlatBuffer` that owns the buffer and its allocator and
/// behaves similar to a `unique_ptr` with a deleter.
FLATBUFFERS_ATTRIBUTE(deprecated("use Release() instead"))
DetachedBuffer ReleaseBufferPointer() {
- Finished();
- return buf_.release();
- }
-
+ Finished();
+ return buf_.release();
+ }
+
/// @brief Get the released DetachedBuffer.
/// @return A `DetachedBuffer` that owns the buffer and its allocator.
DetachedBuffer Release() {
@@ -1305,179 +1305,179 @@ class FlatBufferBuilder {
return minalign_;
}
- /// @cond FLATBUFFERS_INTERNAL
- void Finished() const {
- // If you get this assert, you're attempting to get access a buffer
- // which hasn't been finished yet. Be sure to call
- // FlatBufferBuilder::Finish with your root table.
- // If you really need to access an unfinished buffer, call
- // GetCurrentBufferPointer instead.
+ /// @cond FLATBUFFERS_INTERNAL
+ void Finished() const {
+ // If you get this assert, you're attempting to get access a buffer
+ // which hasn't been finished yet. Be sure to call
+ // FlatBufferBuilder::Finish with your root table.
+ // If you really need to access an unfinished buffer, call
+ // GetCurrentBufferPointer instead.
FLATBUFFERS_ASSERT(finished);
- }
- /// @endcond
-
- /// @brief In order to save space, fields that are set to their default value
- /// don't get serialized into the buffer.
+ }
+ /// @endcond
+
+ /// @brief In order to save space, fields that are set to their default value
+ /// don't get serialized into the buffer.
/// @param[in] fd When set to `true`, always serializes default values that
/// are set. Optional fields which are not set explicitly, will still not be
/// serialized.
- void ForceDefaults(bool fd) { force_defaults_ = fd; }
-
+ void ForceDefaults(bool fd) { force_defaults_ = fd; }
+
/// @brief By default vtables are deduped in order to save space.
/// @param[in] dedup When set to `true`, dedup vtables.
void DedupVtables(bool dedup) { dedup_vtables_ = dedup; }
- /// @cond FLATBUFFERS_INTERNAL
- void Pad(size_t num_bytes) { buf_.fill(num_bytes); }
-
+ /// @cond FLATBUFFERS_INTERNAL
+ void Pad(size_t num_bytes) { buf_.fill(num_bytes); }
+
void TrackMinAlign(size_t elem_size) {
if (elem_size > minalign_) minalign_ = elem_size;
}
- void Align(size_t elem_size) {
+ void Align(size_t elem_size) {
TrackMinAlign(elem_size);
- buf_.fill(PaddingBytes(buf_.size(), elem_size));
- }
-
- void PushFlatBuffer(const uint8_t *bytes, size_t size) {
- PushBytes(bytes, size);
- finished = true;
- }
-
+ buf_.fill(PaddingBytes(buf_.size(), elem_size));
+ }
+
+ void PushFlatBuffer(const uint8_t *bytes, size_t size) {
+ PushBytes(bytes, size);
+ finished = true;
+ }
+
void PushBytes(const uint8_t *bytes, size_t size) { buf_.push(bytes, size); }
-
- void PopBytes(size_t amount) { buf_.pop(amount); }
-
- template<typename T> void AssertScalarT() {
- // The code assumes power of 2 sizes and endian-swap-ability.
+
+ void PopBytes(size_t amount) { buf_.pop(amount); }
+
+ template<typename T> void AssertScalarT() {
+ // The code assumes power of 2 sizes and endian-swap-ability.
static_assert(flatbuffers::is_scalar<T>::value, "T must be a scalar type");
- }
-
- // Write a single aligned scalar to the buffer
- template<typename T> uoffset_t PushElement(T element) {
- AssertScalarT<T>();
- T litle_endian_element = EndianScalar(element);
- Align(sizeof(T));
+ }
+
+ // Write a single aligned scalar to the buffer
+ template<typename T> uoffset_t PushElement(T element) {
+ AssertScalarT<T>();
+ T litle_endian_element = EndianScalar(element);
+ Align(sizeof(T));
buf_.push_small(litle_endian_element);
- return GetSize();
- }
-
- template<typename T> uoffset_t PushElement(Offset<T> off) {
- // Special case for offsets: see ReferTo below.
- return PushElement(ReferTo(off.o));
- }
-
- // When writing fields, we track where they are, so we can create correct
- // vtables later.
- void TrackField(voffset_t field, uoffset_t off) {
- FieldLoc fl = { off, field };
+ return GetSize();
+ }
+
+ template<typename T> uoffset_t PushElement(Offset<T> off) {
+ // Special case for offsets: see ReferTo below.
+ return PushElement(ReferTo(off.o));
+ }
+
+ // When writing fields, we track where they are, so we can create correct
+ // vtables later.
+ void TrackField(voffset_t field, uoffset_t off) {
+ FieldLoc fl = { off, field };
buf_.scratch_push_small(fl);
num_field_loc++;
max_voffset_ = (std::max)(max_voffset_, field);
- }
-
- // Like PushElement, but additionally tracks the field this represents.
- template<typename T> void AddElement(voffset_t field, T e, T def) {
- // We don't serialize values equal to the default.
+ }
+
+ // Like PushElement, but additionally tracks the field this represents.
+ template<typename T> void AddElement(voffset_t field, T e, T def) {
+ // We don't serialize values equal to the default.
if (IsTheSameAs(e, def) && !force_defaults_) return;
- auto off = PushElement(e);
- TrackField(field, off);
- }
-
+ auto off = PushElement(e);
+ TrackField(field, off);
+ }
+
template<typename T> void AddElement(voffset_t field, T e) {
auto off = PushElement(e);
TrackField(field, off);
}
- template<typename T> void AddOffset(voffset_t field, Offset<T> off) {
+ template<typename T> void AddOffset(voffset_t field, Offset<T> off) {
if (off.IsNull()) return; // Don't store.
- AddElement(field, ReferTo(off.o), static_cast<uoffset_t>(0));
- }
-
- template<typename T> void AddStruct(voffset_t field, const T *structptr) {
- if (!structptr) return; // Default, don't store.
- Align(AlignOf<T>());
+ AddElement(field, ReferTo(off.o), static_cast<uoffset_t>(0));
+ }
+
+ template<typename T> void AddStruct(voffset_t field, const T *structptr) {
+ if (!structptr) return; // Default, don't store.
+ Align(AlignOf<T>());
buf_.push_small(*structptr);
- TrackField(field, GetSize());
- }
-
- void AddStructOffset(voffset_t field, uoffset_t off) {
- TrackField(field, off);
- }
-
- // Offsets initially are relative to the end of the buffer (downwards).
- // This function converts them to be relative to the current location
- // in the buffer (when stored here), pointing upwards.
- uoffset_t ReferTo(uoffset_t off) {
- // Align to ensure GetSize() below is correct.
- Align(sizeof(uoffset_t));
- // Offset must refer to something already in buffer.
+ TrackField(field, GetSize());
+ }
+
+ void AddStructOffset(voffset_t field, uoffset_t off) {
+ TrackField(field, off);
+ }
+
+ // Offsets initially are relative to the end of the buffer (downwards).
+ // This function converts them to be relative to the current location
+ // in the buffer (when stored here), pointing upwards.
+ uoffset_t ReferTo(uoffset_t off) {
+ // Align to ensure GetSize() below is correct.
+ Align(sizeof(uoffset_t));
+ // Offset must refer to something already in buffer.
FLATBUFFERS_ASSERT(off && off <= GetSize());
return GetSize() - off + static_cast<uoffset_t>(sizeof(uoffset_t));
- }
-
- void NotNested() {
- // If you hit this, you're trying to construct a Table/Vector/String
- // during the construction of its parent table (between the MyTableBuilder
- // and table.Finish().
- // Move the creation of these sub-objects to above the MyTableBuilder to
- // not get this assert.
- // Ignoring this assert may appear to work in simple cases, but the reason
- // it is here is that storing objects in-line may cause vtable offsets
- // to not fit anymore. It also leads to vtable duplication.
+ }
+
+ void NotNested() {
+ // If you hit this, you're trying to construct a Table/Vector/String
+ // during the construction of its parent table (between the MyTableBuilder
+ // and table.Finish().
+ // Move the creation of these sub-objects to above the MyTableBuilder to
+ // not get this assert.
+ // Ignoring this assert may appear to work in simple cases, but the reason
+ // it is here is that storing objects in-line may cause vtable offsets
+ // to not fit anymore. It also leads to vtable duplication.
FLATBUFFERS_ASSERT(!nested);
// If you hit this, fields were added outside the scope of a table.
FLATBUFFERS_ASSERT(!num_field_loc);
- }
-
- // From generated code (or from the parser), we call StartTable/EndTable
- // with a sequence of AddElement calls in between.
- uoffset_t StartTable() {
- NotNested();
- nested = true;
- return GetSize();
- }
-
- // This finishes one serialized object by generating the vtable if it's a
- // table, comparing it against existing vtables, and writing the
- // resulting vtable offset.
+ }
+
+ // From generated code (or from the parser), we call StartTable/EndTable
+ // with a sequence of AddElement calls in between.
+ uoffset_t StartTable() {
+ NotNested();
+ nested = true;
+ return GetSize();
+ }
+
+ // This finishes one serialized object by generating the vtable if it's a
+ // table, comparing it against existing vtables, and writing the
+ // resulting vtable offset.
uoffset_t EndTable(uoffset_t start) {
- // If you get this assert, a corresponding StartTable wasn't called.
+ // If you get this assert, a corresponding StartTable wasn't called.
FLATBUFFERS_ASSERT(nested);
- // Write the vtable offset, which is the start of any Table.
- // We fill it's value later.
- auto vtableoffsetloc = PushElement<soffset_t>(0);
- // Write a vtable, which consists entirely of voffset_t elements.
- // It starts with the number of offsets, followed by a type id, followed
- // by the offsets themselves. In reverse:
+ // Write the vtable offset, which is the start of any Table.
+ // We fill it's value later.
+ auto vtableoffsetloc = PushElement<soffset_t>(0);
+ // Write a vtable, which consists entirely of voffset_t elements.
+ // It starts with the number of offsets, followed by a type id, followed
+ // by the offsets themselves. In reverse:
// Include space for the last offset and ensure empty tables have a
// minimum size.
max_voffset_ =
(std::max)(static_cast<voffset_t>(max_voffset_ + sizeof(voffset_t)),
FieldIndexToOffset(0));
buf_.fill_big(max_voffset_);
- auto table_object_size = vtableoffsetloc - start;
+ auto table_object_size = vtableoffsetloc - start;
// Vtable use 16bit offsets.
FLATBUFFERS_ASSERT(table_object_size < 0x10000);
WriteScalar<voffset_t>(buf_.data() + sizeof(voffset_t),
static_cast<voffset_t>(table_object_size));
WriteScalar<voffset_t>(buf_.data(), max_voffset_);
- // Write the offsets into the table
+ // Write the offsets into the table
for (auto it = buf_.scratch_end() - num_field_loc * sizeof(FieldLoc);
it < buf_.scratch_end(); it += sizeof(FieldLoc)) {
auto field_location = reinterpret_cast<FieldLoc *>(it);
- auto pos = static_cast<voffset_t>(vtableoffsetloc - field_location->off);
- // If this asserts, it means you've set a field twice.
+ auto pos = static_cast<voffset_t>(vtableoffsetloc - field_location->off);
+ // If this asserts, it means you've set a field twice.
FLATBUFFERS_ASSERT(
!ReadScalar<voffset_t>(buf_.data() + field_location->id));
- WriteScalar<voffset_t>(buf_.data() + field_location->id, pos);
- }
+ WriteScalar<voffset_t>(buf_.data() + field_location->id, pos);
+ }
ClearOffsets();
- auto vt1 = reinterpret_cast<voffset_t *>(buf_.data());
- auto vt1_size = ReadScalar<voffset_t>(vt1);
- auto vt_use = GetSize();
- // See if we already have generated a vtable with this exact same
- // layout before. If so, make it point to the old one, remove this one.
+ auto vt1 = reinterpret_cast<voffset_t *>(buf_.data());
+ auto vt1_size = ReadScalar<voffset_t>(vt1);
+ auto vt_use = GetSize();
+ // See if we already have generated a vtable with this exact same
+ // layout before. If so, make it point to the old one, remove this one.
if (dedup_vtables_) {
for (auto it = buf_.scratch_data(); it < buf_.scratch_end();
it += sizeof(uoffset_t)) {
@@ -1489,76 +1489,76 @@ class FlatBufferBuilder {
buf_.pop(GetSize() - vtableoffsetloc);
break;
}
- }
- // If this is a new vtable, remember it.
+ }
+ // If this is a new vtable, remember it.
if (vt_use == GetSize()) { buf_.scratch_push_small(vt_use); }
- // Fill the vtable offset we created above.
- // The offset points from the beginning of the object to where the
- // vtable is stored.
- // Offsets default direction is downward in memory for future format
- // flexibility (storing all vtables at the start of the file).
- WriteScalar(buf_.data_at(vtableoffsetloc),
- static_cast<soffset_t>(vt_use) -
+ // Fill the vtable offset we created above.
+ // The offset points from the beginning of the object to where the
+ // vtable is stored.
+ // Offsets default direction is downward in memory for future format
+ // flexibility (storing all vtables at the start of the file).
+ WriteScalar(buf_.data_at(vtableoffsetloc),
+ static_cast<soffset_t>(vt_use) -
static_cast<soffset_t>(vtableoffsetloc));
-
- nested = false;
- return vtableoffsetloc;
- }
-
+
+ nested = false;
+ return vtableoffsetloc;
+ }
+
FLATBUFFERS_ATTRIBUTE(deprecated("call the version above instead"))
uoffset_t EndTable(uoffset_t start, voffset_t /*numfields*/) {
return EndTable(start);
}
- // This checks a required field has been set in a given table that has
- // just been constructed.
+ // This checks a required field has been set in a given table that has
+ // just been constructed.
template<typename T> void Required(Offset<T> table, voffset_t field);
-
- uoffset_t StartStruct(size_t alignment) {
- Align(alignment);
- return GetSize();
- }
-
- uoffset_t EndStruct() { return GetSize(); }
-
+
+ uoffset_t StartStruct(size_t alignment) {
+ Align(alignment);
+ return GetSize();
+ }
+
+ uoffset_t EndStruct() { return GetSize(); }
+
void ClearOffsets() {
buf_.scratch_pop(num_field_loc * sizeof(FieldLoc));
num_field_loc = 0;
max_voffset_ = 0;
}
-
- // Aligns such that when "len" bytes are written, an object can be written
- // after it with "alignment" without padding.
- void PreAlign(size_t len, size_t alignment) {
+
+ // Aligns such that when "len" bytes are written, an object can be written
+ // after it with "alignment" without padding.
+ void PreAlign(size_t len, size_t alignment) {
TrackMinAlign(alignment);
- buf_.fill(PaddingBytes(GetSize() + len, alignment));
- }
- template<typename T> void PreAlign(size_t len) {
- AssertScalarT<T>();
- PreAlign(len, sizeof(T));
- }
- /// @endcond
-
- /// @brief Store a string in the buffer, which can contain any binary data.
- /// @param[in] str A const char pointer to the data to be stored as a string.
- /// @param[in] len The number of bytes that should be stored from `str`.
- /// @return Returns the offset in the buffer where the string starts.
- Offset<String> CreateString(const char *str, size_t len) {
- NotNested();
- PreAlign<uoffset_t>(len + 1); // Always 0-terminated.
- buf_.fill(1);
- PushBytes(reinterpret_cast<const uint8_t *>(str), len);
- PushElement(static_cast<uoffset_t>(len));
- return Offset<String>(GetSize());
- }
-
+ buf_.fill(PaddingBytes(GetSize() + len, alignment));
+ }
+ template<typename T> void PreAlign(size_t len) {
+ AssertScalarT<T>();
+ PreAlign(len, sizeof(T));
+ }
+ /// @endcond
+
+ /// @brief Store a string in the buffer, which can contain any binary data.
+ /// @param[in] str A const char pointer to the data to be stored as a string.
+ /// @param[in] len The number of bytes that should be stored from `str`.
+ /// @return Returns the offset in the buffer where the string starts.
+ Offset<String> CreateString(const char *str, size_t len) {
+ NotNested();
+ PreAlign<uoffset_t>(len + 1); // Always 0-terminated.
+ buf_.fill(1);
+ PushBytes(reinterpret_cast<const uint8_t *>(str), len);
+ PushElement(static_cast<uoffset_t>(len));
+ return Offset<String>(GetSize());
+ }
+
/// @brief Store a string in the buffer, which is null-terminated.
- /// @param[in] str A const char pointer to a C-string to add to the buffer.
- /// @return Returns the offset in the buffer where the string starts.
- Offset<String> CreateString(const char *str) {
- return CreateString(str, strlen(str));
- }
-
+ /// @param[in] str A const char pointer to a C-string to add to the buffer.
+ /// @return Returns the offset in the buffer where the string starts.
+ Offset<String> CreateString(const char *str) {
+ return CreateString(str, strlen(str));
+ }
+
/// @brief Store a string in the buffer, which is null-terminated.
/// @param[in] str A char pointer to a C-string to add to the buffer.
/// @return Returns the offset in the buffer where the string starts.
@@ -1566,16 +1566,16 @@ class FlatBufferBuilder {
return CreateString(str, strlen(str));
}
- /// @brief Store a string in the buffer, which can contain any binary data.
- /// @param[in] str A const reference to a std::string to store in the buffer.
- /// @return Returns the offset in the buffer where the string starts.
- Offset<String> CreateString(const std::string &str) {
- return CreateString(str.c_str(), str.length());
- }
-
+ /// @brief Store a string in the buffer, which can contain any binary data.
+ /// @param[in] str A const reference to a std::string to store in the buffer.
+ /// @return Returns the offset in the buffer where the string starts.
+ Offset<String> CreateString(const std::string &str) {
+ return CreateString(str.c_str(), str.length());
+ }
+
// clang-format off
#ifdef FLATBUFFERS_HAS_STRING_VIEW
- /// @brief Store a string in the buffer, which can contain any binary data.
+ /// @brief Store a string in the buffer, which can contain any binary data.
/// @param[in] str A const string_view to copy in to the buffer.
/// @return Returns the offset in the buffer where the string starts.
Offset<String> CreateString(flatbuffers::string_view str) {
@@ -1585,12 +1585,12 @@ class FlatBufferBuilder {
// clang-format on
/// @brief Store a string in the buffer, which can contain any binary data.
- /// @param[in] str A const pointer to a `String` struct to add to the buffer.
- /// @return Returns the offset in the buffer where the string starts
- Offset<String> CreateString(const String *str) {
+ /// @param[in] str A const pointer to a `String` struct to add to the buffer.
+ /// @return Returns the offset in the buffer where the string starts
+ Offset<String> CreateString(const String *str) {
return str ? CreateString(str->c_str(), str->size()) : 0;
- }
-
+ }
+
/// @brief Store a string in the buffer, which can contain any binary data.
/// @param[in] str A const reference to a std::string like type with support
/// of T::c_str() and T::length() to store in the buffer.
@@ -1662,50 +1662,50 @@ class FlatBufferBuilder {
return CreateSharedString(str->c_str(), str->size());
}
- /// @cond FLATBUFFERS_INTERNAL
- uoffset_t EndVector(size_t len) {
+ /// @cond FLATBUFFERS_INTERNAL
+ uoffset_t EndVector(size_t len) {
FLATBUFFERS_ASSERT(nested); // Hit if no corresponding StartVector.
- nested = false;
- return PushElement(static_cast<uoffset_t>(len));
- }
-
- void StartVector(size_t len, size_t elemsize) {
- NotNested();
- nested = true;
- PreAlign<uoffset_t>(len * elemsize);
- PreAlign(len * elemsize, elemsize); // Just in case elemsize > uoffset_t.
- }
-
- // Call this right before StartVector/CreateVector if you want to force the
- // alignment to be something different than what the element size would
- // normally dictate.
- // This is useful when storing a nested_flatbuffer in a vector of bytes,
- // or when storing SIMD floats, etc.
- void ForceVectorAlignment(size_t len, size_t elemsize, size_t alignment) {
+ nested = false;
+ return PushElement(static_cast<uoffset_t>(len));
+ }
+
+ void StartVector(size_t len, size_t elemsize) {
+ NotNested();
+ nested = true;
+ PreAlign<uoffset_t>(len * elemsize);
+ PreAlign(len * elemsize, elemsize); // Just in case elemsize > uoffset_t.
+ }
+
+ // Call this right before StartVector/CreateVector if you want to force the
+ // alignment to be something different than what the element size would
+ // normally dictate.
+ // This is useful when storing a nested_flatbuffer in a vector of bytes,
+ // or when storing SIMD floats, etc.
+ void ForceVectorAlignment(size_t len, size_t elemsize, size_t alignment) {
FLATBUFFERS_ASSERT(VerifyAlignmentRequirements(alignment));
- PreAlign(len * elemsize, alignment);
- }
-
+ PreAlign(len * elemsize, alignment);
+ }
+
// Similar to ForceVectorAlignment but for String fields.
void ForceStringAlignment(size_t len, size_t alignment) {
FLATBUFFERS_ASSERT(VerifyAlignmentRequirements(alignment));
PreAlign((len + 1) * sizeof(char), alignment);
- }
-
- /// @endcond
-
- /// @brief Serialize an array into a FlatBuffer `vector`.
- /// @tparam T The data type of the array elements.
- /// @param[in] v A pointer to the array of type `T` to serialize into the
- /// buffer as a `vector`.
- /// @param[in] len The number of elements to serialize.
- /// @return Returns a typed `Offset` into the serialized data indicating
- /// where the vector is stored.
- template<typename T> Offset<Vector<T>> CreateVector(const T *v, size_t len) {
+ }
+
+ /// @endcond
+
+ /// @brief Serialize an array into a FlatBuffer `vector`.
+ /// @tparam T The data type of the array elements.
+ /// @param[in] v A pointer to the array of type `T` to serialize into the
+ /// buffer as a `vector`.
+ /// @param[in] len The number of elements to serialize.
+ /// @return Returns a typed `Offset` into the serialized data indicating
+ /// where the vector is stored.
+ template<typename T> Offset<Vector<T>> CreateVector(const T *v, size_t len) {
// If this assert hits, you're specifying a template argument that is
// causing the wrong overload to be selected, remove it.
AssertScalarT<T>();
- StartVector(len, sizeof(T));
+ StartVector(len, sizeof(T));
if (len == 0) { return Offset<Vector<T>>(EndVector(len)); }
// clang-format off
#if FLATBUFFERS_LITTLEENDIAN
@@ -1728,18 +1728,18 @@ class FlatBufferBuilder {
StartVector(len, sizeof(Offset<T>));
for (auto i = len; i > 0;) { PushElement(v[--i]); }
return Offset<Vector<Offset<T>>>(EndVector(len));
- }
-
- /// @brief Serialize a `std::vector` into a FlatBuffer `vector`.
- /// @tparam T The data type of the `std::vector` elements.
- /// @param v A const reference to the `std::vector` to serialize into the
- /// buffer as a `vector`.
- /// @return Returns a typed `Offset` into the serialized data indicating
- /// where the vector is stored.
- template<typename T> Offset<Vector<T>> CreateVector(const std::vector<T> &v) {
+ }
+
+ /// @brief Serialize a `std::vector` into a FlatBuffer `vector`.
+ /// @tparam T The data type of the `std::vector` elements.
+ /// @param v A const reference to the `std::vector` to serialize into the
+ /// buffer as a `vector`.
+ /// @return Returns a typed `Offset` into the serialized data indicating
+ /// where the vector is stored.
+ template<typename T> Offset<Vector<T>> CreateVector(const std::vector<T> &v) {
return CreateVector(data(v), v.size());
- }
-
+ }
+
// vector<bool> may be implemented using a bit-set, so we can't access it as
// an array. Instead, read elements manually.
// Background: https://isocpp.org/blog/2012/11/on-vectorbool
@@ -1798,20 +1798,20 @@ class FlatBufferBuilder {
return CreateVector(offsets);
}
- /// @brief Serialize an array of structs into a FlatBuffer `vector`.
- /// @tparam T The data type of the struct array elements.
- /// @param[in] v A pointer to the array of type `T` to serialize into the
- /// buffer as a `vector`.
- /// @param[in] len The number of elements to serialize.
- /// @return Returns a typed `Offset` into the serialized data indicating
- /// where the vector is stored.
+ /// @brief Serialize an array of structs into a FlatBuffer `vector`.
+ /// @tparam T The data type of the struct array elements.
+ /// @param[in] v A pointer to the array of type `T` to serialize into the
+ /// buffer as a `vector`.
+ /// @param[in] len The number of elements to serialize.
+ /// @return Returns a typed `Offset` into the serialized data indicating
+ /// where the vector is stored.
template<typename T>
Offset<Vector<const T *>> CreateVectorOfStructs(const T *v, size_t len) {
- StartVector(len * sizeof(T) / AlignOf<T>(), AlignOf<T>());
- PushBytes(reinterpret_cast<const uint8_t *>(v), sizeof(T) * len);
- return Offset<Vector<const T *>>(EndVector(len));
- }
-
+ StartVector(len * sizeof(T) / AlignOf<T>(), AlignOf<T>());
+ PushBytes(reinterpret_cast<const uint8_t *>(v), sizeof(T) * len);
+ return Offset<Vector<const T *>>(EndVector(len));
+ }
+
/// @brief Serialize an array of native structs into a FlatBuffer `vector`.
/// @tparam T The data type of the struct array elements.
/// @tparam S The data type of the native struct array elements.
@@ -1888,18 +1888,18 @@ class FlatBufferBuilder {
return EndVectorOfStructs<T>(vector_size);
}
- /// @brief Serialize a `std::vector` of structs into a FlatBuffer `vector`.
- /// @tparam T The data type of the `std::vector` struct elements.
+ /// @brief Serialize a `std::vector` of structs into a FlatBuffer `vector`.
+ /// @tparam T The data type of the `std::vector` struct elements.
/// @param[in] v A const reference to the `std::vector` of structs to
- /// serialize into the buffer as a `vector`.
- /// @return Returns a typed `Offset` into the serialized data indicating
- /// where the vector is stored.
+ /// serialize into the buffer as a `vector`.
+ /// @return Returns a typed `Offset` into the serialized data indicating
+ /// where the vector is stored.
template<typename T, typename Alloc>
Offset<Vector<const T *>> CreateVectorOfStructs(
const std::vector<T, Alloc> &v) {
return CreateVectorOfStructs(data(v), v.size());
- }
-
+ }
+
/// @brief Serialize a `std::vector` of native structs into a FlatBuffer
/// `vector`.
/// @tparam T The data type of the `std::vector` struct elements.
@@ -1930,7 +1930,7 @@ class FlatBufferBuilder {
return CreateVectorOfNativeStructs<T, S>(data(v), v.size());
}
- /// @cond FLATBUFFERS_INTERNAL
+ /// @cond FLATBUFFERS_INTERNAL
template<typename T> struct StructKeyComparator {
bool operator()(const T &a, const T &b) const {
return a.KeyCompareLessThan(&b);
@@ -2004,80 +2004,80 @@ class FlatBufferBuilder {
template<typename T> struct TableKeyComparator {
TableKeyComparator(vector_downward &buf) : buf_(buf) {}
TableKeyComparator(const TableKeyComparator &other) : buf_(other.buf_) {}
- bool operator()(const Offset<T> &a, const Offset<T> &b) const {
- auto table_a = reinterpret_cast<T *>(buf_.data_at(a.o));
- auto table_b = reinterpret_cast<T *>(buf_.data_at(b.o));
- return table_a->KeyCompareLessThan(table_b);
- }
+ bool operator()(const Offset<T> &a, const Offset<T> &b) const {
+ auto table_a = reinterpret_cast<T *>(buf_.data_at(a.o));
+ auto table_b = reinterpret_cast<T *>(buf_.data_at(b.o));
+ return table_a->KeyCompareLessThan(table_b);
+ }
vector_downward &buf_;
-
+
private:
FLATBUFFERS_DELETE_FUNC(
TableKeyComparator &operator=(const TableKeyComparator &other));
- };
- /// @endcond
-
- /// @brief Serialize an array of `table` offsets as a `vector` in the buffer
- /// in sorted order.
- /// @tparam T The data type that the offset refers to.
- /// @param[in] v An array of type `Offset<T>` that contains the `table`
- /// offsets to store in the buffer in sorted order.
- /// @param[in] len The number of elements to store in the `vector`.
- /// @return Returns a typed `Offset` into the serialized data indicating
- /// where the vector is stored.
+ };
+ /// @endcond
+
+ /// @brief Serialize an array of `table` offsets as a `vector` in the buffer
+ /// in sorted order.
+ /// @tparam T The data type that the offset refers to.
+ /// @param[in] v An array of type `Offset<T>` that contains the `table`
+ /// offsets to store in the buffer in sorted order.
+ /// @param[in] len The number of elements to store in the `vector`.
+ /// @return Returns a typed `Offset` into the serialized data indicating
+ /// where the vector is stored.
template<typename T>
Offset<Vector<Offset<T>>> CreateVectorOfSortedTables(Offset<T> *v,
size_t len) {
- std::sort(v, v + len, TableKeyComparator<T>(buf_));
- return CreateVector(v, len);
- }
-
- /// @brief Serialize an array of `table` offsets as a `vector` in the buffer
- /// in sorted order.
- /// @tparam T The data type that the offset refers to.
- /// @param[in] v An array of type `Offset<T>` that contains the `table`
- /// offsets to store in the buffer in sorted order.
- /// @return Returns a typed `Offset` into the serialized data indicating
- /// where the vector is stored.
+ std::sort(v, v + len, TableKeyComparator<T>(buf_));
+ return CreateVector(v, len);
+ }
+
+ /// @brief Serialize an array of `table` offsets as a `vector` in the buffer
+ /// in sorted order.
+ /// @tparam T The data type that the offset refers to.
+ /// @param[in] v An array of type `Offset<T>` that contains the `table`
+ /// offsets to store in the buffer in sorted order.
+ /// @return Returns a typed `Offset` into the serialized data indicating
+ /// where the vector is stored.
template<typename T>
Offset<Vector<Offset<T>>> CreateVectorOfSortedTables(
std::vector<Offset<T>> *v) {
return CreateVectorOfSortedTables(data(*v), v->size());
- }
-
- /// @brief Specialized version of `CreateVector` for non-copying use cases.
- /// Write the data any time later to the returned buffer pointer `buf`.
- /// @param[in] len The number of elements to store in the `vector`.
- /// @param[in] elemsize The size of each element in the `vector`.
- /// @param[out] buf A pointer to a `uint8_t` pointer that can be
- /// written to at a later time to serialize the data into a `vector`
- /// in the buffer.
- uoffset_t CreateUninitializedVector(size_t len, size_t elemsize,
- uint8_t **buf) {
- NotNested();
- StartVector(len, elemsize);
+ }
+
+ /// @brief Specialized version of `CreateVector` for non-copying use cases.
+ /// Write the data any time later to the returned buffer pointer `buf`.
+ /// @param[in] len The number of elements to store in the `vector`.
+ /// @param[in] elemsize The size of each element in the `vector`.
+ /// @param[out] buf A pointer to a `uint8_t` pointer that can be
+ /// written to at a later time to serialize the data into a `vector`
+ /// in the buffer.
+ uoffset_t CreateUninitializedVector(size_t len, size_t elemsize,
+ uint8_t **buf) {
+ NotNested();
+ StartVector(len, elemsize);
buf_.make_space(len * elemsize);
auto vec_start = GetSize();
auto vec_end = EndVector(len);
*buf = buf_.data_at(vec_start);
return vec_end;
- }
-
- /// @brief Specialized version of `CreateVector` for non-copying use cases.
- /// Write the data any time later to the returned buffer pointer `buf`.
- /// @tparam T The data type of the data that will be stored in the buffer
- /// as a `vector`.
- /// @param[in] len The number of elements to store in the `vector`.
- /// @param[out] buf A pointer to a pointer of type `T` that can be
- /// written to at a later time to serialize the data into a `vector`
- /// in the buffer.
+ }
+
+ /// @brief Specialized version of `CreateVector` for non-copying use cases.
+ /// Write the data any time later to the returned buffer pointer `buf`.
+ /// @tparam T The data type of the data that will be stored in the buffer
+ /// as a `vector`.
+ /// @param[in] len The number of elements to store in the `vector`.
+ /// @param[out] buf A pointer to a pointer of type `T` that can be
+ /// written to at a later time to serialize the data into a `vector`
+ /// in the buffer.
template<typename T>
Offset<Vector<T>> CreateUninitializedVector(size_t len, T **buf) {
AssertScalarT<T>();
- return CreateUninitializedVector(len, sizeof(T),
- reinterpret_cast<uint8_t **>(buf));
- }
-
+ return CreateUninitializedVector(len, sizeof(T),
+ reinterpret_cast<uint8_t **>(buf));
+ }
+
template<typename T>
Offset<Vector<const T *>> CreateUninitializedVectorOfStructs(size_t len,
T **buf) {
@@ -2105,12 +2105,12 @@ class FlatBufferBuilder {
return Offset<const T *>(GetSize());
}
- /// @brief The length of a FlatBuffer file header.
- static const size_t kFileIdentifierLength = 4;
-
- /// @brief Finish serializing a buffer by writing the root offset.
- /// @param[in] file_identifier If a `file_identifier` is given, the buffer
- /// will be prefixed with a standard FlatBuffers file header.
+ /// @brief The length of a FlatBuffer file header.
+ static const size_t kFileIdentifierLength = 4;
+
+ /// @brief Finish serializing a buffer by writing the root offset.
+ /// @param[in] file_identifier If a `file_identifier` is given, the buffer
+ /// will be prefixed with a standard FlatBuffers file header.
template<typename T>
void Finish(Offset<T> root, const char *file_identifier = nullptr) {
Finish(root.o, file_identifier, false);
@@ -2139,45 +2139,45 @@ class FlatBufferBuilder {
FlatBufferBuilder &operator=(const FlatBufferBuilder &);
void Finish(uoffset_t root, const char *file_identifier, bool size_prefix) {
- NotNested();
+ NotNested();
buf_.clear_scratch();
- // This will cause the whole buffer to be aligned.
+ // This will cause the whole buffer to be aligned.
PreAlign((size_prefix ? sizeof(uoffset_t) : 0) + sizeof(uoffset_t) +
(file_identifier ? kFileIdentifierLength : 0),
- minalign_);
- if (file_identifier) {
+ minalign_);
+ if (file_identifier) {
FLATBUFFERS_ASSERT(strlen(file_identifier) == kFileIdentifierLength);
PushBytes(reinterpret_cast<const uint8_t *>(file_identifier),
- kFileIdentifierLength);
- }
+ kFileIdentifierLength);
+ }
PushElement(ReferTo(root)); // Location of root.
if (size_prefix) { PushElement(GetSize()); }
- finished = true;
- }
-
- struct FieldLoc {
- uoffset_t off;
- voffset_t id;
- };
-
- vector_downward buf_;
-
- // Accumulating offsets of table members while it is being built.
+ finished = true;
+ }
+
+ struct FieldLoc {
+ uoffset_t off;
+ voffset_t id;
+ };
+
+ vector_downward buf_;
+
+ // Accumulating offsets of table members while it is being built.
// We store these in the scratch pad of buf_, after the vtable offsets.
uoffset_t num_field_loc;
// Track how much of the vtable is in use, so we can output the most compact
// possible vtable.
voffset_t max_voffset_;
-
- // Ensure objects are not nested.
- bool nested;
-
- // Ensure the buffer is finished before it is being accessed.
- bool finished;
-
- size_t minalign_;
-
- bool force_defaults_; // Serialize values equal to their defaults anyway.
+
+ // Ensure objects are not nested.
+ bool nested;
+
+ // Ensure the buffer is finished before it is being accessed.
+ bool finished;
+
+ size_t minalign_;
+
+ bool force_defaults_; // Serialize values equal to their defaults anyway.
bool dedup_vtables_;
@@ -2210,22 +2210,22 @@ class FlatBufferBuilder {
Offset<Vector<const T *>> EndVectorOfStructs(size_t vector_size) {
return Offset<Vector<const T *>>(EndVector(vector_size));
}
-};
-/// @}
-
-/// @cond FLATBUFFERS_INTERNAL
-// Helpers to get a typed pointer to the root object contained in the buffer.
-template<typename T> T *GetMutableRoot(void *buf) {
- EndianCheck();
+};
+/// @}
+
+/// @cond FLATBUFFERS_INTERNAL
+// Helpers to get a typed pointer to the root object contained in the buffer.
+template<typename T> T *GetMutableRoot(void *buf) {
+ EndianCheck();
return reinterpret_cast<T *>(
reinterpret_cast<uint8_t *>(buf) +
EndianScalar(*reinterpret_cast<uoffset_t *>(buf)));
-}
-
-template<typename T> const T *GetRoot(const void *buf) {
- return GetMutableRoot<T>(const_cast<void *>(buf));
-}
-
+}
+
+template<typename T> const T *GetRoot(const void *buf) {
+ return GetMutableRoot<T>(const_cast<void *>(buf));
+}
+
template<typename T> const T *GetSizePrefixedRoot(const void *buf) {
return GetRoot<T>(reinterpret_cast<const uint8_t *>(buf) + sizeof(uoffset_t));
}
@@ -2257,16 +2257,16 @@ inline const char *GetBufferIdentifier(const void *buf,
((size_prefixed) ? 2 * sizeof(uoffset_t) : sizeof(uoffset_t));
}
-// Helper to see if the identifier in a buffer has the expected value.
+// Helper to see if the identifier in a buffer has the expected value.
inline bool BufferHasIdentifier(const void *buf, const char *identifier,
bool size_prefixed = false) {
return strncmp(GetBufferIdentifier(buf, size_prefixed), identifier,
FlatBufferBuilder::kFileIdentifierLength) == 0;
-}
-
-// Helper class to verify the integrity of a FlatBuffer
-class Verifier FLATBUFFERS_FINAL_CLASS {
- public:
+}
+
+// Helper class to verify the integrity of a FlatBuffer
+class Verifier FLATBUFFERS_FINAL_CLASS {
+ public:
Verifier(const uint8_t *buf, size_t buf_len, uoffset_t _max_depth = 64,
uoffset_t _max_tables = 1000000, bool _check_alignment = true)
: buf_(buf),
@@ -2279,22 +2279,22 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
check_alignment_(_check_alignment) {
FLATBUFFERS_ASSERT(size_ < FLATBUFFERS_MAX_BUFFER_SIZE);
}
-
- // Central location where any verification failures register.
- bool Check(bool ok) const {
+
+ // Central location where any verification failures register.
+ bool Check(bool ok) const {
// clang-format off
- #ifdef FLATBUFFERS_DEBUG_VERIFICATION_FAILURE
+ #ifdef FLATBUFFERS_DEBUG_VERIFICATION_FAILURE
FLATBUFFERS_ASSERT(ok);
- #endif
+ #endif
#ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
if (!ok)
upper_bound_ = 0;
#endif
// clang-format on
- return ok;
- }
-
- // Verify any range within the buffer.
+ return ok;
+ }
+
+ // Verify any range within the buffer.
bool Verify(size_t elem, size_t elem_len) const {
// clang-format off
#ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
@@ -2304,17 +2304,17 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
#endif
// clang-format on
return Check(elem_len < size_ && elem <= size_ - elem_len);
- }
-
+ }
+
template<typename T> bool VerifyAlignment(size_t elem) const {
return Check((elem & (sizeof(T) - 1)) == 0 || !check_alignment_);
}
- // Verify a range indicated by sizeof(T).
+ // Verify a range indicated by sizeof(T).
template<typename T> bool Verify(size_t elem) const {
return VerifyAlignment<T>(elem) && Verify(elem, sizeof(T));
- }
-
+ }
+
bool VerifyFromPointer(const uint8_t *p, size_t len) {
auto o = static_cast<size_t>(p - buf_);
return Verify(o, len);
@@ -2330,68 +2330,68 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
return Verify(static_cast<size_t>(base - buf_) + elem_off, sizeof(T));
}
- // Verify a pointer (may be NULL) of a table type.
- template<typename T> bool VerifyTable(const T *table) {
- return !table || table->Verify(*this);
- }
-
- // Verify a pointer (may be NULL) of any vector type.
+ // Verify a pointer (may be NULL) of a table type.
+ template<typename T> bool VerifyTable(const T *table) {
+ return !table || table->Verify(*this);
+ }
+
+ // Verify a pointer (may be NULL) of any vector type.
template<typename T> bool VerifyVector(const Vector<T> *vec) const {
return !vec || VerifyVectorOrString(reinterpret_cast<const uint8_t *>(vec),
sizeof(T));
- }
-
- // Verify a pointer (may be NULL) of a vector to struct.
+ }
+
+ // Verify a pointer (may be NULL) of a vector to struct.
template<typename T> bool VerifyVector(const Vector<const T *> *vec) const {
return VerifyVector(reinterpret_cast<const Vector<T> *>(vec));
- }
-
- // Verify a pointer (may be NULL) to string.
+ }
+
+ // Verify a pointer (may be NULL) to string.
bool VerifyString(const String *str) const {
size_t end;
return !str || (VerifyVectorOrString(reinterpret_cast<const uint8_t *>(str),
1, &end) &&
Verify(end, 1) && // Must have terminator
Check(buf_[end] == '\0')); // Terminating byte must be 0.
- }
-
- // Common code between vectors and strings.
+ }
+
+ // Common code between vectors and strings.
bool VerifyVectorOrString(const uint8_t *vec, size_t elem_size,
size_t *end = nullptr) const {
auto veco = static_cast<size_t>(vec - buf_);
- // Check we can read the size field.
+ // Check we can read the size field.
if (!Verify<uoffset_t>(veco)) return false;
- // Check the whole array. If this is a string, the byte past the array
- // must be 0.
- auto size = ReadScalar<uoffset_t>(vec);
+ // Check the whole array. If this is a string, the byte past the array
+ // must be 0.
+ auto size = ReadScalar<uoffset_t>(vec);
auto max_elems = FLATBUFFERS_MAX_BUFFER_SIZE / elem_size;
if (!Check(size < max_elems))
return false; // Protect against byte_size overflowing.
- auto byte_size = sizeof(size) + elem_size * size;
+ auto byte_size = sizeof(size) + elem_size * size;
if (end) *end = veco + byte_size;
return Verify(veco, byte_size);
- }
-
- // Special case for string contents, after the above has been called.
- bool VerifyVectorOfStrings(const Vector<Offset<String>> *vec) const {
+ }
+
+ // Special case for string contents, after the above has been called.
+ bool VerifyVectorOfStrings(const Vector<Offset<String>> *vec) const {
if (vec) {
for (uoffset_t i = 0; i < vec->size(); i++) {
if (!VerifyString(vec->Get(i))) return false;
- }
+ }
}
return true;
- }
-
- // Special case for table contents, after the above has been called.
- template<typename T> bool VerifyVectorOfTables(const Vector<Offset<T>> *vec) {
- if (vec) {
- for (uoffset_t i = 0; i < vec->size(); i++) {
- if (!vec->Get(i)->Verify(*this)) return false;
- }
- }
- return true;
- }
-
+ }
+
+ // Special case for table contents, after the above has been called.
+ template<typename T> bool VerifyVectorOfTables(const Vector<Offset<T>> *vec) {
+ if (vec) {
+ for (uoffset_t i = 0; i < vec->size(); i++) {
+ if (!vec->Get(i)->Verify(*this)) return false;
+ }
+ }
+ return true;
+ }
+
__supress_ubsan__("unsigned-integer-overflow") bool VerifyTableStart(
const uint8_t *table) {
// Check the vtable offset.
@@ -2424,7 +2424,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
// clang-format on
}
- // Verify this whole buffer, starting with root type T.
+ // Verify this whole buffer, starting with root type T.
template<typename T> bool VerifyBuffer() { return VerifyBuffer<T>(nullptr); }
template<typename T> bool VerifyBuffer(const char *identifier) {
@@ -2435,8 +2435,8 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
return Verify<uoffset_t>(0U) &&
ReadScalar<uoffset_t>(buf_) == size_ - sizeof(uoffset_t) &&
VerifyBufferFromStart<T>(identifier, sizeof(uoffset_t));
- }
-
+ }
+
uoffset_t VerifyOffset(size_t start) const {
if (!Verify<uoffset_t>(start)) return 0;
auto o = ReadScalar<uoffset_t>(buf_ + start);
@@ -2454,22 +2454,22 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
return VerifyOffset(static_cast<size_t>(base - buf_) + start);
}
- // 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
- // with EndTable().
- bool VerifyComplexity() {
- depth_++;
- num_tables_++;
- return Check(depth_ <= max_depth_ && num_tables_ <= max_tables_);
- }
-
- // Called at the end of a table to pop the depth count.
- bool EndTable() {
- depth_--;
- return true;
- }
-
+ // 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
+ // with EndTable().
+ bool VerifyComplexity() {
+ depth_++;
+ num_tables_++;
+ return Check(depth_ <= max_depth_ && num_tables_ <= max_tables_);
+ }
+
+ // Called at the end of a table to pop the depth count.
+ bool EndTable() {
+ depth_--;
+ return true;
+ }
+
// Returns the message size in bytes
size_t GetComputedSize() const {
// clang-format off
@@ -2487,8 +2487,8 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
// clang-format on
}
- private:
- const uint8_t *buf_;
+ private:
+ const uint8_t *buf_;
size_t size_;
uoffset_t depth_;
uoffset_t max_depth_;
@@ -2496,8 +2496,8 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
uoffset_t max_tables_;
mutable size_t upper_bound_;
bool check_alignment_;
-};
-
+};
+
// Convenient way to bundle a buffer and its length, to pass it around
// typed by its root.
// A BufferRef does not own its buffer.
@@ -2523,74 +2523,74 @@ template<typename T> struct BufferRef : BufferRefBase {
bool must_free;
};
-// "structs" are flat structures that do not have an offset table, thus
-// always have all members present and do not support forwards/backwards
-// compatible extensions.
-
-class Struct FLATBUFFERS_FINAL_CLASS {
- public:
- template<typename T> T GetField(uoffset_t o) const {
- return ReadScalar<T>(&data_[o]);
- }
-
- template<typename T> T GetStruct(uoffset_t o) const {
- return reinterpret_cast<T>(&data_[o]);
- }
-
- const uint8_t *GetAddressOf(uoffset_t o) const { return &data_[o]; }
- uint8_t *GetAddressOf(uoffset_t o) { return &data_[o]; }
-
- private:
+// "structs" are flat structures that do not have an offset table, thus
+// always have all members present and do not support forwards/backwards
+// compatible extensions.
+
+class Struct FLATBUFFERS_FINAL_CLASS {
+ public:
+ template<typename T> T GetField(uoffset_t o) const {
+ return ReadScalar<T>(&data_[o]);
+ }
+
+ template<typename T> T GetStruct(uoffset_t o) const {
+ return reinterpret_cast<T>(&data_[o]);
+ }
+
+ const uint8_t *GetAddressOf(uoffset_t o) const { return &data_[o]; }
+ uint8_t *GetAddressOf(uoffset_t o) { return &data_[o]; }
+
+ private:
// private constructor & copy constructor: you obtain instances of this
// class by pointing to existing data only
Struct();
Struct(const Struct &);
Struct &operator=(const Struct &);
- uint8_t data_[1];
-};
-
-// "tables" use an offset table (possibly shared) that allows fields to be
-// omitted and added at will, but uses an extra indirection to read.
-class Table {
- public:
+ uint8_t data_[1];
+};
+
+// "tables" use an offset table (possibly shared) that allows fields to be
+// omitted and added at will, but uses an extra indirection to read.
+class Table {
+ public:
const uint8_t *GetVTable() const {
return data_ - ReadScalar<soffset_t>(data_);
}
- // This gets the field offset for any of the functions below it, or 0
- // if the field was not present.
- voffset_t GetOptionalFieldOffset(voffset_t field) const {
- // The vtable offset is always at the start.
+ // This gets the field offset for any of the functions below it, or 0
+ // if the field was not present.
+ voffset_t GetOptionalFieldOffset(voffset_t field) const {
+ // The vtable offset is always at the start.
auto vtable = GetVTable();
- // The first element is the size of the vtable (fields + type id + itself).
- auto vtsize = ReadScalar<voffset_t>(vtable);
- // If the field we're accessing is outside the vtable, we're reading older
- // data, so it's the same as if the offset was 0 (not present).
- return field < vtsize ? ReadScalar<voffset_t>(vtable + field) : 0;
- }
-
- template<typename T> T GetField(voffset_t field, T defaultval) const {
- auto field_offset = GetOptionalFieldOffset(field);
- return field_offset ? ReadScalar<T>(data_ + field_offset) : defaultval;
- }
-
- template<typename P> P GetPointer(voffset_t field) {
- auto field_offset = GetOptionalFieldOffset(field);
- auto p = data_ + field_offset;
+ // The first element is the size of the vtable (fields + type id + itself).
+ auto vtsize = ReadScalar<voffset_t>(vtable);
+ // If the field we're accessing is outside the vtable, we're reading older
+ // data, so it's the same as if the offset was 0 (not present).
+ return field < vtsize ? ReadScalar<voffset_t>(vtable + field) : 0;
+ }
+
+ template<typename T> T GetField(voffset_t field, T defaultval) const {
+ auto field_offset = GetOptionalFieldOffset(field);
+ return field_offset ? ReadScalar<T>(data_ + field_offset) : defaultval;
+ }
+
+ template<typename P> P GetPointer(voffset_t field) {
+ auto field_offset = GetOptionalFieldOffset(field);
+ auto p = data_ + field_offset;
return field_offset ? reinterpret_cast<P>(p + ReadScalar<uoffset_t>(p))
: nullptr;
- }
- template<typename P> P GetPointer(voffset_t field) const {
- return const_cast<Table *>(this)->GetPointer<P>(field);
- }
-
- template<typename P> P GetStruct(voffset_t field) const {
- auto field_offset = GetOptionalFieldOffset(field);
- auto p = const_cast<uint8_t *>(data_ + field_offset);
- return field_offset ? reinterpret_cast<P>(p) : nullptr;
- }
-
+ }
+ template<typename P> P GetPointer(voffset_t field) const {
+ return const_cast<Table *>(this)->GetPointer<P>(field);
+ }
+
+ template<typename P> P GetStruct(voffset_t field) const {
+ auto field_offset = GetOptionalFieldOffset(field);
+ auto p = const_cast<uint8_t *>(data_ + field_offset);
+ return field_offset ? reinterpret_cast<P>(p) : nullptr;
+ }
+
template<typename Raw, typename Face>
flatbuffers::Optional<Face> GetOptional(voffset_t field) const {
auto field_offset = GetOptionalFieldOffset(field);
@@ -2600,62 +2600,62 @@ class Table {
}
template<typename T> bool SetField(voffset_t field, T val, T def) {
- auto field_offset = GetOptionalFieldOffset(field);
+ auto field_offset = GetOptionalFieldOffset(field);
if (!field_offset) return IsTheSameAs(val, def);
- WriteScalar(data_ + field_offset, val);
- return true;
- }
+ WriteScalar(data_ + field_offset, val);
+ return true;
+ }
template<typename T> bool SetField(voffset_t field, T val) {
auto field_offset = GetOptionalFieldOffset(field);
if (!field_offset) return false;
WriteScalar(data_ + field_offset, val);
return true;
}
-
- bool SetPointer(voffset_t field, const uint8_t *val) {
- auto field_offset = GetOptionalFieldOffset(field);
- if (!field_offset) return false;
+
+ bool SetPointer(voffset_t field, const uint8_t *val) {
+ auto field_offset = GetOptionalFieldOffset(field);
+ if (!field_offset) return false;
WriteScalar(data_ + field_offset,
static_cast<uoffset_t>(val - (data_ + field_offset)));
- return true;
- }
-
- uint8_t *GetAddressOf(voffset_t field) {
- auto field_offset = GetOptionalFieldOffset(field);
- return field_offset ? data_ + field_offset : nullptr;
- }
- const uint8_t *GetAddressOf(voffset_t field) const {
- return const_cast<Table *>(this)->GetAddressOf(field);
- }
-
- bool CheckField(voffset_t field) const {
- return GetOptionalFieldOffset(field) != 0;
- }
-
- // Verify the vtable of this table.
- // Call this once per table, followed by VerifyField once per field.
- bool VerifyTableStart(Verifier &verifier) const {
+ return true;
+ }
+
+ uint8_t *GetAddressOf(voffset_t field) {
+ auto field_offset = GetOptionalFieldOffset(field);
+ return field_offset ? data_ + field_offset : nullptr;
+ }
+ const uint8_t *GetAddressOf(voffset_t field) const {
+ return const_cast<Table *>(this)->GetAddressOf(field);
+ }
+
+ bool CheckField(voffset_t field) const {
+ return GetOptionalFieldOffset(field) != 0;
+ }
+
+ // Verify the vtable of this table.
+ // Call this once per table, followed by VerifyField once per field.
+ bool VerifyTableStart(Verifier &verifier) const {
return verifier.VerifyTableStart(data_);
- }
-
- // Verify a particular field.
+ }
+
+ // Verify a particular field.
template<typename T>
bool VerifyField(const Verifier &verifier, voffset_t field) const {
- // Calling GetOptionalFieldOffset should be safe now thanks to
- // VerifyTable().
- auto field_offset = GetOptionalFieldOffset(field);
- // Check the actual field.
+ // Calling GetOptionalFieldOffset should be safe now thanks to
+ // VerifyTable().
+ auto field_offset = GetOptionalFieldOffset(field);
+ // Check the actual field.
return !field_offset || verifier.Verify<T>(data_, field_offset);
- }
-
- // VerifyField for required fields.
+ }
+
+ // VerifyField for required fields.
template<typename T>
bool VerifyFieldRequired(const Verifier &verifier, voffset_t field) const {
- auto field_offset = GetOptionalFieldOffset(field);
- return verifier.Check(field_offset != 0) &&
+ 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);
@@ -2668,16 +2668,16 @@ class Table {
verifier.VerifyOffset(data_, field_offset);
}
- private:
- // private constructor & copy constructor: you obtain instances of this
- // class by pointing to existing data only
- Table();
- Table(const Table &other);
+ private:
+ // private constructor & copy constructor: you obtain instances of this
+ // class by pointing to existing data only
+ Table();
+ Table(const Table &other);
Table &operator=(const Table &);
-
- uint8_t data_[1];
-};
-
+
+ uint8_t data_[1];
+};
+
// This specialization allows avoiding warnings like:
// MSVC C4800: type: forcing value to bool 'true' or 'false'.
template<>
@@ -2766,59 +2766,59 @@ typedef uint64_t hash_value_t;
#endif
// clang-format on
-// Helper function to test if a field is present, using any of the field
-// enums in the generated code.
-// `table` must be a generated table type. Since this is a template parameter,
-// this is not typechecked to be a subclass of Table, so beware!
-// Note: this function will return false for fields equal to the default
-// value, since they're not stored in the buffer (unless force_defaults was
-// used).
+// Helper function to test if a field is present, using any of the field
+// enums in the generated code.
+// `table` must be a generated table type. Since this is a template parameter,
+// this is not typechecked to be a subclass of Table, so beware!
+// Note: this function will return false for fields equal to the default
+// value, since they're not stored in the buffer (unless force_defaults was
+// used).
template<typename T>
bool IsFieldPresent(const T *table, typename T::FlatBuffersVTableOffset field) {
- // Cast, since Table is a private baseclass of any table types.
+ // Cast, since Table is a private baseclass of any table types.
return reinterpret_cast<const Table *>(table)->CheckField(
static_cast<voffset_t>(field));
-}
-
-// Utility function for reverse lookups on the EnumNames*() functions
-// (in the generated C++ code)
-// names must be NULL terminated.
-inline int LookupEnum(const char **names, const char *name) {
- for (const char **p = names; *p; p++)
+}
+
+// Utility function for reverse lookups on the EnumNames*() functions
+// (in the generated C++ code)
+// names must be NULL terminated.
+inline int LookupEnum(const char **names, const char *name) {
+ for (const char **p = names; *p; p++)
if (!strcmp(*p, name)) return static_cast<int>(p - names);
- return -1;
-}
-
-// These macros allow us to layout a struct with a guarantee that they'll end
-// up looking the same on different compilers and platforms.
-// It does this by disallowing the compiler to do any padding, and then
-// does padding itself by inserting extra padding fields that make every
-// element aligned to its own size.
-// Additionally, it manually sets the alignment of the struct as a whole,
-// which is typically its largest element, or a custom size set in the schema
-// by the force_align attribute.
-// These are used in the generated code only.
-
+ return -1;
+}
+
+// These macros allow us to layout a struct with a guarantee that they'll end
+// up looking the same on different compilers and platforms.
+// It does this by disallowing the compiler to do any padding, and then
+// does padding itself by inserting extra padding fields that make every
+// element aligned to its own size.
+// Additionally, it manually sets the alignment of the struct as a whole,
+// which is typically its largest element, or a custom size set in the schema
+// by the force_align attribute.
+// These are used in the generated code only.
+
// clang-format off
-#if defined(_MSC_VER)
+#if defined(_MSC_VER)
#define FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(alignment) \
__pragma(pack(1)) \
- struct __declspec(align(alignment))
+ struct __declspec(align(alignment))
#define FLATBUFFERS_STRUCT_END(name, size) \
__pragma(pack()) \
- static_assert(sizeof(name) == size, "compiler breaks packing rules")
+ static_assert(sizeof(name) == size, "compiler breaks packing rules")
#elif defined(__GNUC__) || defined(__clang__) || defined(__ICCARM__)
#define FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(alignment) \
- _Pragma("pack(1)") \
- struct __attribute__((aligned(alignment)))
+ _Pragma("pack(1)") \
+ struct __attribute__((aligned(alignment)))
#define FLATBUFFERS_STRUCT_END(name, size) \
- _Pragma("pack()") \
- static_assert(sizeof(name) == size, "compiler breaks packing rules")
-#else
- #error Unknown compiler, please define structure alignment macros
-#endif
+ _Pragma("pack()") \
+ static_assert(sizeof(name) == size, "compiler breaks packing rules")
+#else
+ #error Unknown compiler, please define structure alignment macros
+#endif
// clang-format on
-
+
// Minimal reflection via code generation.
// Besides full-fat reflection (see reflection.h) and parsing/printing by
// loading schemas (see idl.h), we can also have code generation for mimimal
@@ -2895,28 +2895,28 @@ struct TypeTable {
const char *const *names; // Only set if compiled with --reflect-names.
};
-// String which identifies the current version of FlatBuffers.
-// flatbuffer_version_string is used by Google developers to identify which
-// applications uploaded to Google Play are using this library. This allows
-// the development team at Google to determine the popularity of the library.
-// How it works: Applications that are uploaded to the Google Play Store are
-// scanned for this version string. We track which applications are using it
-// to measure popularity. You are free to remove it (of course) but we would
-// appreciate if you left it in.
-
-// Weak linkage is culled by VS & doesn't work on cygwin.
+// String which identifies the current version of FlatBuffers.
+// flatbuffer_version_string is used by Google developers to identify which
+// applications uploaded to Google Play are using this library. This allows
+// the development team at Google to determine the popularity of the library.
+// How it works: Applications that are uploaded to the Google Play Store are
+// scanned for this version string. We track which applications are using it
+// to measure popularity. You are free to remove it (of course) but we would
+// appreciate if you left it in.
+
+// Weak linkage is culled by VS & doesn't work on cygwin.
// clang-format off
-#if !defined(_WIN32) && !defined(__CYGWIN__)
-
-extern volatile __attribute__((weak)) const char *flatbuffer_version_string;
-volatile __attribute__((weak)) const char *flatbuffer_version_string =
- "FlatBuffers "
- FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MAJOR) "."
- FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MINOR) "."
- FLATBUFFERS_STRING(FLATBUFFERS_VERSION_REVISION);
-
-#endif // !defined(_WIN32) && !defined(__CYGWIN__)
-
+#if !defined(_WIN32) && !defined(__CYGWIN__)
+
+extern volatile __attribute__((weak)) const char *flatbuffer_version_string;
+volatile __attribute__((weak)) const char *flatbuffer_version_string =
+ "FlatBuffers "
+ FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MAJOR) "."
+ FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MINOR) "."
+ FLATBUFFERS_STRING(FLATBUFFERS_VERSION_REVISION);
+
+#endif // !defined(_WIN32) && !defined(__CYGWIN__)
+
#define FLATBUFFERS_DEFINE_BITMASK_OPERATORS(E, T)\
inline E operator | (E lhs, E rhs){\
return E(T(lhs) | T(rhs));\
@@ -2946,9 +2946,9 @@ volatile __attribute__((weak)) const char *flatbuffer_version_string =
{\
return !bool(T(rhs)); \
}
-/// @endcond
-} // namespace flatbuffers
-
+/// @endcond
+} // namespace flatbuffers
+
// clang-format on
-#endif // FLATBUFFERS_H_
+#endif // FLATBUFFERS_H_
diff --git a/contrib/libs/flatbuffers/include/flatbuffers/hash.h b/contrib/libs/flatbuffers/include/flatbuffers/hash.h
index 1a2d62913a..52cc628cdf 100644
--- a/contrib/libs/flatbuffers/include/flatbuffers/hash.h
+++ b/contrib/libs/flatbuffers/include/flatbuffers/hash.h
@@ -1,62 +1,62 @@
-/*
- * Copyright 2015 Google Inc. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef FLATBUFFERS_HASH_H_
-#define FLATBUFFERS_HASH_H_
-
-#include <cstdint>
-#include <cstring>
-
+/*
+ * Copyright 2015 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FLATBUFFERS_HASH_H_
+#define FLATBUFFERS_HASH_H_
+
+#include <cstdint>
+#include <cstring>
+
#include "flatbuffers.h"
-
-namespace flatbuffers {
-
+
+namespace flatbuffers {
+
template<typename T> struct FnvTraits {
- static const T kFnvPrime;
- static const T kOffsetBasis;
-};
-
+ static const T kFnvPrime;
+ static const T kOffsetBasis;
+};
+
template<> struct FnvTraits<uint32_t> {
- static const uint32_t kFnvPrime = 0x01000193;
- static const uint32_t kOffsetBasis = 0x811C9DC5;
-};
-
+ static const uint32_t kFnvPrime = 0x01000193;
+ static const uint32_t kOffsetBasis = 0x811C9DC5;
+};
+
template<> struct FnvTraits<uint64_t> {
- static const uint64_t kFnvPrime = 0x00000100000001b3ULL;
- static const uint64_t kOffsetBasis = 0xcbf29ce484222645ULL;
-};
-
+ static const uint64_t kFnvPrime = 0x00000100000001b3ULL;
+ static const uint64_t kOffsetBasis = 0xcbf29ce484222645ULL;
+};
+
template<typename T> T HashFnv1(const char *input) {
- T hash = FnvTraits<T>::kOffsetBasis;
- for (const char *c = input; *c; ++c) {
- hash *= FnvTraits<T>::kFnvPrime;
- hash ^= static_cast<unsigned char>(*c);
- }
- return hash;
-}
-
+ T hash = FnvTraits<T>::kOffsetBasis;
+ for (const char *c = input; *c; ++c) {
+ hash *= FnvTraits<T>::kFnvPrime;
+ hash ^= static_cast<unsigned char>(*c);
+ }
+ return hash;
+}
+
template<typename T> T HashFnv1a(const char *input) {
- T hash = FnvTraits<T>::kOffsetBasis;
- for (const char *c = input; *c; ++c) {
- hash ^= static_cast<unsigned char>(*c);
- hash *= FnvTraits<T>::kFnvPrime;
- }
- return hash;
-}
-
+ T hash = FnvTraits<T>::kOffsetBasis;
+ for (const char *c = input; *c; ++c) {
+ hash ^= static_cast<unsigned char>(*c);
+ hash *= FnvTraits<T>::kFnvPrime;
+ }
+ return hash;
+}
+
template<> inline uint16_t HashFnv1<uint16_t>(const char *input) {
uint32_t hash = HashFnv1<uint32_t>(input);
return (hash >> 16) ^ (hash & 0xffff);
@@ -68,27 +68,27 @@ template<> inline uint16_t HashFnv1a<uint16_t>(const char *input) {
}
template<typename T> struct NamedHashFunction {
- const char *name;
-
+ const char *name;
+
typedef T (*HashFunction)(const char *);
- HashFunction function;
-};
-
+ HashFunction function;
+};
+
const NamedHashFunction<uint16_t> kHashFunctions16[] = {
{ "fnv1_16", HashFnv1<uint16_t> },
{ "fnv1a_16", HashFnv1a<uint16_t> },
};
-const NamedHashFunction<uint32_t> kHashFunctions32[] = {
+const NamedHashFunction<uint32_t> kHashFunctions32[] = {
{ "fnv1_32", HashFnv1<uint32_t> },
- { "fnv1a_32", HashFnv1a<uint32_t> },
-};
-
-const NamedHashFunction<uint64_t> kHashFunctions64[] = {
+ { "fnv1a_32", HashFnv1a<uint32_t> },
+};
+
+const NamedHashFunction<uint64_t> kHashFunctions64[] = {
{ "fnv1_64", HashFnv1<uint64_t> },
- { "fnv1a_64", HashFnv1a<uint64_t> },
-};
-
+ { "fnv1a_64", HashFnv1a<uint64_t> },
+};
+
inline NamedHashFunction<uint16_t>::HashFunction FindHashFunction16(
const char *name) {
std::size_t size = sizeof(kHashFunctions16) / sizeof(kHashFunctions16[0]);
@@ -100,28 +100,28 @@ inline NamedHashFunction<uint16_t>::HashFunction FindHashFunction16(
return nullptr;
}
-inline NamedHashFunction<uint32_t>::HashFunction FindHashFunction32(
- const char *name) {
- std::size_t size = sizeof(kHashFunctions32) / sizeof(kHashFunctions32[0]);
- for (std::size_t i = 0; i < size; ++i) {
- if (std::strcmp(name, kHashFunctions32[i].name) == 0) {
- return kHashFunctions32[i].function;
- }
- }
- return nullptr;
-}
-
-inline NamedHashFunction<uint64_t>::HashFunction FindHashFunction64(
- const char *name) {
- std::size_t size = sizeof(kHashFunctions64) / sizeof(kHashFunctions64[0]);
- for (std::size_t i = 0; i < size; ++i) {
- if (std::strcmp(name, kHashFunctions64[i].name) == 0) {
- return kHashFunctions64[i].function;
- }
- }
- return nullptr;
-}
-
-} // namespace flatbuffers
-
-#endif // FLATBUFFERS_HASH_H_
+inline NamedHashFunction<uint32_t>::HashFunction FindHashFunction32(
+ const char *name) {
+ std::size_t size = sizeof(kHashFunctions32) / sizeof(kHashFunctions32[0]);
+ for (std::size_t i = 0; i < size; ++i) {
+ if (std::strcmp(name, kHashFunctions32[i].name) == 0) {
+ return kHashFunctions32[i].function;
+ }
+ }
+ return nullptr;
+}
+
+inline NamedHashFunction<uint64_t>::HashFunction FindHashFunction64(
+ const char *name) {
+ std::size_t size = sizeof(kHashFunctions64) / sizeof(kHashFunctions64[0]);
+ for (std::size_t i = 0; i < size; ++i) {
+ if (std::strcmp(name, kHashFunctions64[i].name) == 0) {
+ return kHashFunctions64[i].function;
+ }
+ }
+ return nullptr;
+}
+
+} // namespace flatbuffers
+
+#endif // FLATBUFFERS_HASH_H_
diff --git a/contrib/libs/flatbuffers/include/flatbuffers/idl.h b/contrib/libs/flatbuffers/include/flatbuffers/idl.h
index fea4636150..a82ff8a694 100644
--- a/contrib/libs/flatbuffers/include/flatbuffers/idl.h
+++ b/contrib/libs/flatbuffers/include/flatbuffers/idl.h
@@ -1,52 +1,52 @@
-/*
- * Copyright 2014 Google Inc. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef FLATBUFFERS_IDL_H_
-#define FLATBUFFERS_IDL_H_
-
-#include <map>
+/*
+ * Copyright 2014 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FLATBUFFERS_IDL_H_
+#define FLATBUFFERS_IDL_H_
+
+#include <map>
#include <memory>
-#include <stack>
-
+#include <stack>
+
#include "base.h"
#include "flatbuffers.h"
#include "flexbuffers.h"
#include "hash.h"
#include "reflection.h"
-
+
#if !defined(FLATBUFFERS_CPP98_STL)
# include <functional>
#endif // !defined(FLATBUFFERS_CPP98_STL)
-// This file defines the data types representing a parsed IDL (Interface
-// Definition Language) / schema file.
-
+// This file defines the data types representing a parsed IDL (Interface
+// Definition Language) / schema file.
+
// Limits maximum depth of nested objects.
// Prevents stack overflow while parse scheme, or json, or flexbuffer.
#if !defined(FLATBUFFERS_MAX_PARSING_DEPTH)
# define FLATBUFFERS_MAX_PARSING_DEPTH 64
#endif
-namespace flatbuffers {
-
-// The order of these matters for Is*() functions below.
-// Additionally, Parser::ParseType assumes bool..string is a contiguous range
-// of type tokens.
+namespace flatbuffers {
+
+// The order of these matters for Is*() functions below.
+// Additionally, Parser::ParseType assumes bool..string is a contiguous range
+// of type tokens.
// clang-format off
-#define FLATBUFFERS_GEN_TYPES_SCALAR(TD) \
+#define FLATBUFFERS_GEN_TYPES_SCALAR(TD) \
TD(NONE, "", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8) \
TD(UTYPE, "", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8) /* begin scalar/int */ \
TD(BOOL, "bool", uint8_t, boolean,bool, bool, bool, bool, Boolean, Bool) \
@@ -60,37 +60,37 @@ namespace flatbuffers {
TD(ULONG, "ulong", uint64_t, long, uint64, ulong, uint64, u64, ULong, UInt64) /* end int */ \
TD(FLOAT, "float", float, float, float32, float, float32, f32, Float, Float32) /* begin float */ \
TD(DOUBLE, "double", double, double, float64, double, float64, f64, Double, Double) /* end float/scalar */
-#define FLATBUFFERS_GEN_TYPES_POINTER(TD) \
+#define FLATBUFFERS_GEN_TYPES_POINTER(TD) \
TD(STRING, "string", Offset<void>, int, int, StringOffset, int, unused, Int, Offset<String>) \
TD(VECTOR, "", Offset<void>, int, int, VectorOffset, int, unused, Int, Offset<UOffset>) \
TD(STRUCT, "", Offset<void>, int, int, int, int, unused, Int, Offset<UOffset>) \
TD(UNION, "", Offset<void>, int, int, int, int, unused, Int, Offset<UOffset>)
#define FLATBUFFERS_GEN_TYPE_ARRAY(TD) \
TD(ARRAY, "", int, int, int, int, int, unused, Int, Offset<UOffset>)
-// The fields are:
-// - enum
-// - FlatBuffers schema type.
-// - C++ type.
-// - Java type.
-// - Go type.
-// - C# / .Net type.
-// - Python type.
+// The fields are:
+// - enum
+// - FlatBuffers schema type.
+// - C++ type.
+// - Java type.
+// - Go type.
+// - C# / .Net type.
+// - Python type.
// - Rust type.
// - Kotlin type.
-
-// using these macros, we can now write code dealing with types just once, e.g.
-
-/*
-switch (type) {
+
+// using these macros, we can now write code dealing with types just once, e.g.
+
+/*
+switch (type) {
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, \
RTYPE, KTYPE) \
- case BASE_TYPE_ ## ENUM: \
- // do something specific to CTYPE here
- FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
- #undef FLATBUFFERS_TD
-}
-*/
-
+ case BASE_TYPE_ ## ENUM: \
+ // do something specific to CTYPE here
+ FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
+ #undef FLATBUFFERS_TD
+}
+*/
+
// If not all FLATBUFFERS_GEN_() arguments are necessary for implementation
// of FLATBUFFERS_TD, you can use a variadic macro (with __VA_ARGS__ if needed).
// In the above example, only CTYPE is used to generate the code, it can be rewritten:
@@ -105,34 +105,34 @@ switch (type) {
}
*/
-#define FLATBUFFERS_GEN_TYPES(TD) \
- FLATBUFFERS_GEN_TYPES_SCALAR(TD) \
+#define FLATBUFFERS_GEN_TYPES(TD) \
+ FLATBUFFERS_GEN_TYPES_SCALAR(TD) \
FLATBUFFERS_GEN_TYPES_POINTER(TD) \
FLATBUFFERS_GEN_TYPE_ARRAY(TD)
-
-// Create an enum for all the types above.
-#ifdef __GNUC__
-__extension__ // Stop GCC complaining about trailing comma with -Wpendantic.
-#endif
-enum BaseType {
+
+// Create an enum for all the types above.
+#ifdef __GNUC__
+__extension__ // Stop GCC complaining about trailing comma with -Wpendantic.
+#endif
+enum BaseType {
#define FLATBUFFERS_TD(ENUM, ...) \
BASE_TYPE_ ## ENUM,
- FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
- #undef FLATBUFFERS_TD
-};
-
+ FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
+ #undef FLATBUFFERS_TD
+};
+
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \
static_assert(sizeof(CTYPE) <= sizeof(largest_scalar_t), \
"define largest_scalar_t as " #CTYPE);
- FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
-#undef FLATBUFFERS_TD
-
-inline bool IsScalar (BaseType t) { return t >= BASE_TYPE_UTYPE &&
- t <= BASE_TYPE_DOUBLE; }
-inline bool IsInteger(BaseType t) { return t >= BASE_TYPE_UTYPE &&
- t <= BASE_TYPE_ULONG; }
-inline bool IsFloat (BaseType t) { return t == BASE_TYPE_FLOAT ||
- t == BASE_TYPE_DOUBLE; }
+ FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
+#undef FLATBUFFERS_TD
+
+inline bool IsScalar (BaseType t) { return t >= BASE_TYPE_UTYPE &&
+ t <= BASE_TYPE_DOUBLE; }
+inline bool IsInteger(BaseType t) { return t >= BASE_TYPE_UTYPE &&
+ t <= BASE_TYPE_ULONG; }
+inline bool IsFloat (BaseType t) { return t == BASE_TYPE_FLOAT ||
+ t == BASE_TYPE_DOUBLE; }
inline bool IsLong (BaseType t) { return t == BASE_TYPE_LONG ||
t == BASE_TYPE_ULONG; }
inline bool IsBool (BaseType t) { return t == BASE_TYPE_BOOL; }
@@ -146,19 +146,19 @@ inline bool IsUnsigned(BaseType t) {
}
// clang-format on
-
-extern const char *const kTypeNames[];
-extern const char kTypeSizes[];
-
+
+extern const char *const kTypeNames[];
+extern const char kTypeSizes[];
+
inline size_t SizeOf(BaseType t) { return kTypeSizes[t]; }
-
-struct StructDef;
-struct EnumDef;
+
+struct StructDef;
+struct EnumDef;
class Parser;
-
-// Represents any type in the IDL, which is a combination of the BaseType
-// and additional information for vectors/structs_.
-struct Type {
+
+// Represents any type in the IDL, which is a combination of the BaseType
+// and additional information for vectors/structs_.
+struct Type {
explicit Type(BaseType _base_type = BASE_TYPE_NONE, StructDef *_sd = nullptr,
EnumDef *_ed = nullptr, uint16_t _fixed_length = 0)
: base_type(_base_type),
@@ -166,90 +166,90 @@ struct Type {
struct_def(_sd),
enum_def(_ed),
fixed_length(_fixed_length) {}
-
- bool operator==(const Type &o) {
- return base_type == o.base_type && element == o.element &&
- struct_def == o.struct_def && enum_def == o.enum_def;
- }
-
+
+ bool operator==(const Type &o) {
+ return base_type == o.base_type && element == o.element &&
+ struct_def == o.struct_def && enum_def == o.enum_def;
+ }
+
Type VectorType() const {
return Type(element, struct_def, enum_def, fixed_length);
}
-
- Offset<reflection::Type> Serialize(FlatBufferBuilder *builder) const;
-
+
+ Offset<reflection::Type> Serialize(FlatBufferBuilder *builder) const;
+
bool Deserialize(const Parser &parser, const reflection::Type *type);
- BaseType base_type;
- BaseType element; // only set if t == BASE_TYPE_VECTOR
- StructDef *struct_def; // only set if t or element == BASE_TYPE_STRUCT
- EnumDef *enum_def; // set if t == BASE_TYPE_UNION / BASE_TYPE_UTYPE,
- // or for an integral type derived from an enum.
+ BaseType base_type;
+ BaseType element; // only set if t == BASE_TYPE_VECTOR
+ StructDef *struct_def; // only set if t or element == BASE_TYPE_STRUCT
+ EnumDef *enum_def; // set if t == BASE_TYPE_UNION / BASE_TYPE_UTYPE,
+ // or for an integral type derived from an enum.
uint16_t fixed_length; // only set if t == BASE_TYPE_ARRAY
-};
-
-// Represents a parsed scalar value, it's type, and field offset.
-struct Value {
+};
+
+// Represents a parsed scalar value, it's type, and field offset.
+struct Value {
Value()
: constant("0"),
offset(static_cast<voffset_t>(~(static_cast<voffset_t>(0U)))) {}
- Type type;
- std::string constant;
- voffset_t offset;
-};
-
-// Helper class that retains the original order of a set of identifiers and
-// also provides quick lookup.
-template<typename T> class SymbolTable {
- public:
- ~SymbolTable() {
+ Type type;
+ std::string constant;
+ voffset_t offset;
+};
+
+// Helper class that retains the original order of a set of identifiers and
+// also provides quick lookup.
+template<typename T> class SymbolTable {
+ public:
+ ~SymbolTable() {
for (auto it = vec.begin(); it != vec.end(); ++it) { delete *it; }
- }
-
- bool Add(const std::string &name, T *e) {
+ }
+
+ bool Add(const std::string &name, T *e) {
vector_emplace_back(&vec, e);
- auto it = dict.find(name);
- if (it != dict.end()) return true;
- dict[name] = e;
- return false;
- }
-
- void Move(const std::string &oldname, const std::string &newname) {
- auto it = dict.find(oldname);
- if (it != dict.end()) {
- auto obj = it->second;
- dict.erase(it);
- dict[newname] = obj;
- } else {
+ auto it = dict.find(name);
+ if (it != dict.end()) return true;
+ dict[name] = e;
+ return false;
+ }
+
+ void Move(const std::string &oldname, const std::string &newname) {
+ auto it = dict.find(oldname);
+ if (it != dict.end()) {
+ auto obj = it->second;
+ dict.erase(it);
+ dict[newname] = obj;
+ } else {
FLATBUFFERS_ASSERT(false);
- }
- }
-
- T *Lookup(const std::string &name) const {
- auto it = dict.find(name);
- return it == dict.end() ? nullptr : it->second;
- }
-
+ }
+ }
+
+ T *Lookup(const std::string &name) const {
+ auto it = dict.find(name);
+ return it == dict.end() ? nullptr : it->second;
+ }
+
public:
std::map<std::string, T *> dict; // quick lookup
std::vector<T *> vec; // Used to iterate in order of insertion
-};
-
-// A name space, as set in the schema.
-struct Namespace {
+};
+
+// A name space, as set in the schema.
+struct Namespace {
Namespace() : from_table(0) {}
-
+
// Given a (potentially unqualified) name, return the "fully qualified" name
- // which has a full namespaced descriptor.
- // With max_components you can request less than the number of components
- // the current namespace has.
- std::string GetFullyQualifiedName(const std::string &name,
- size_t max_components = 1000) const;
+ // which has a full namespaced descriptor.
+ // With max_components you can request less than the number of components
+ // the current namespace has.
+ std::string GetFullyQualifiedName(const std::string &name,
+ size_t max_components = 1000) const;
std::vector<std::string> components;
size_t from_table; // Part of the namespace corresponds to a message/table.
-};
-
+};
+
inline bool operator<(const Namespace &a, const Namespace &b) {
size_t min_size = std::min(a.components.size(), b.components.size());
for (size_t i = 0; i < min_size; ++i) {
@@ -259,15 +259,15 @@ inline bool operator<(const Namespace &a, const Namespace &b) {
return a.components.size() < b.components.size();
}
-// Base class for all definition types (fields, structs_, enums_).
-struct Definition {
+// Base class for all definition types (fields, structs_, enums_).
+struct Definition {
Definition()
: generated(false),
defined_namespace(nullptr),
serialized_location(0),
index(-1),
refcount(1) {}
-
+
flatbuffers::Offset<
flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>>
SerializeAttributes(FlatBufferBuilder *builder, const Parser &parser) const;
@@ -275,20 +275,20 @@ struct Definition {
bool DeserializeAttributes(Parser &parser,
const Vector<Offset<reflection::KeyValue>> *attrs);
- std::string name;
- std::string file;
- std::vector<std::string> doc_comment;
- SymbolTable<Value> attributes;
- bool generated; // did we already output code for this definition?
- Namespace *defined_namespace; // Where it was defined.
-
- // For use with Serialize()
- uoffset_t serialized_location;
- int index; // Inside the vector it is stored.
+ std::string name;
+ std::string file;
+ std::vector<std::string> doc_comment;
+ SymbolTable<Value> attributes;
+ bool generated; // did we already output code for this definition?
+ Namespace *defined_namespace; // Where it was defined.
+
+ // For use with Serialize()
+ uoffset_t serialized_location;
+ int index; // Inside the vector it is stored.
int refcount;
-};
-
-struct FieldDef : public Definition {
+};
+
+struct FieldDef : public Definition {
FieldDef()
: deprecated(false),
key(false),
@@ -298,10 +298,10 @@ struct FieldDef : public Definition {
presence(kDefault),
nested_flatbuffer(NULL),
padding(0) {}
-
+
Offset<reflection::Field> Serialize(FlatBufferBuilder *builder, uint16_t id,
const Parser &parser) const;
-
+
bool Deserialize(Parser &parser, const reflection::Field *field);
bool IsScalarOptional() const {
@@ -317,7 +317,7 @@ struct FieldDef : public Definition {
return presence == kDefault;
}
- Value value;
+ Value value;
bool deprecated; // Field is allowed to be present in old data, but can't be.
// written in new data nor accessed in new code.
bool key; // Field functions as a key for creating sorted vectors.
@@ -348,56 +348,56 @@ struct FieldDef : public Definition {
StructDef *nested_flatbuffer; // This field contains nested FlatBuffer data.
size_t padding; // Bytes to always pad after this field.
-};
-
-struct StructDef : public Definition {
- StructDef()
+};
+
+struct StructDef : public Definition {
+ StructDef()
: fixed(false),
predecl(true),
sortbysize(true),
has_key(false),
minalign(1),
bytesize(0) {}
-
- void PadLastField(size_t min_align) {
- auto padding = PaddingBytes(bytesize, min_align);
- bytesize += padding;
- if (fields.vec.size()) fields.vec.back()->padding = padding;
- }
-
+
+ void PadLastField(size_t min_align) {
+ auto padding = PaddingBytes(bytesize, min_align);
+ bytesize += padding;
+ if (fields.vec.size()) fields.vec.back()->padding = padding;
+ }
+
Offset<reflection::Object> Serialize(FlatBufferBuilder *builder,
const Parser &parser) const;
-
+
bool Deserialize(Parser &parser, const reflection::Object *object);
- SymbolTable<FieldDef> fields;
+ SymbolTable<FieldDef> fields;
- bool fixed; // If it's struct, not a table.
- bool predecl; // If it's used before it was defined.
- bool sortbysize; // Whether fields come in the declaration or size order.
- bool has_key; // It has a key field.
- size_t minalign; // What the whole object needs to be aligned to.
- size_t bytesize; // Size if fixed.
+ bool fixed; // If it's struct, not a table.
+ bool predecl; // If it's used before it was defined.
+ bool sortbysize; // Whether fields come in the declaration or size order.
+ bool has_key; // It has a key field.
+ size_t minalign; // What the whole object needs to be aligned to.
+ size_t bytesize; // Size if fixed.
flatbuffers::unique_ptr<std::string> original_location;
-};
-
+};
+
struct EnumDef;
struct EnumValBuilder;
-
+
struct EnumVal {
Offset<reflection::EnumVal> Serialize(FlatBufferBuilder *builder,
const Parser &parser) const;
-
+
bool Deserialize(const Parser &parser, const reflection::EnumVal *val);
-
+
uint64_t GetAsUInt64() const { return static_cast<uint64_t>(value); }
int64_t GetAsInt64() const { return value; }
bool IsZero() const { return 0 == value; }
bool IsNonZero() const { return !IsZero(); }
-
- std::string name;
- std::vector<std::string> doc_comment;
+
+ std::string name;
+ std::vector<std::string> doc_comment;
Type union_type;
private:
@@ -408,12 +408,12 @@ struct EnumVal {
EnumVal(const std::string &_name, int64_t _val) : name(_name), value(_val) {}
EnumVal() : value(0) {}
- int64_t value;
-};
-
-struct EnumDef : public Definition {
+ int64_t value;
+};
+
+struct EnumDef : public Definition {
EnumDef() : is_union(false), uses_multiple_type_instances(false) {}
-
+
Offset<reflection::Enum> Serialize(FlatBufferBuilder *builder,
const Parser &parser) const;
@@ -438,21 +438,21 @@ struct EnumDef : public Definition {
std::string ToString(const EnumVal &ev) const {
return IsUInt64() ? NumToString(ev.GetAsUInt64())
: NumToString(ev.GetAsInt64());
- }
-
+ }
+
size_t size() const { return vals.vec.size(); }
-
+
const std::vector<EnumVal *> &Vals() const { return vals.vec; }
const EnumVal *Lookup(const std::string &enum_name) const {
return vals.Lookup(enum_name);
}
- bool is_union;
+ bool is_union;
// Type is a union which uses type aliases where at least one type is
// available under two different names.
bool uses_multiple_type_instances;
- Type underlying_type;
+ Type underlying_type;
private:
bool IsUInt64() const {
@@ -461,8 +461,8 @@ struct EnumDef : public Definition {
friend EnumValBuilder;
SymbolTable<EnumVal> vals;
-};
-
+};
+
inline bool IsString(const Type &type) {
return type.base_type == BASE_TYPE_STRING;
}
@@ -540,24 +540,24 @@ struct ServiceDef : public Definition {
SymbolTable<RPCCall> calls;
};
-// Container of options that may apply to any of the source/text generators.
-struct IDLOptions {
+// Container of options that may apply to any of the source/text generators.
+struct IDLOptions {
bool gen_jvmstatic;
// Use flexbuffers instead for binary and text generation
bool use_flexbuffers;
- bool strict_json;
- bool output_default_scalars_in_json;
- int indent_step;
- bool output_enum_identifiers;
- bool prefixed_enums;
- bool scoped_enums;
- bool include_dependence_headers;
- bool mutable_buffer;
- bool one_file;
- bool proto_mode;
+ bool strict_json;
+ bool output_default_scalars_in_json;
+ int indent_step;
+ bool output_enum_identifiers;
+ bool prefixed_enums;
+ bool scoped_enums;
+ bool include_dependence_headers;
+ bool mutable_buffer;
+ bool one_file;
+ bool proto_mode;
bool proto_oneof_union;
- bool generate_all;
- bool skip_unexpected_fields_in_json;
+ bool generate_all;
+ bool skip_unexpected_fields_in_json;
bool generate_name_strings;
bool generate_object_based_api;
bool gen_compare;
@@ -593,8 +593,8 @@ struct IDLOptions {
std::string filename_suffix;
std::string filename_extension;
bool no_warnings;
-
- // Possible options for the more general generator below.
+
+ // Possible options for the more general generator below.
enum Language {
kJava = 1 << 0,
kCSharp = 1 << 1,
@@ -615,9 +615,9 @@ struct IDLOptions {
kCppYandexMapsIter = 1 << 17,
kMAX
};
-
- Language lang;
-
+
+ Language lang;
+
enum MiniReflect { kNone, kTypes, kTypesAndNames };
MiniReflect mini_reflect;
@@ -637,7 +637,7 @@ struct IDLOptions {
// make the flatbuffer more compact.
bool set_empty_vectors_to_null;
- IDLOptions()
+ IDLOptions()
: gen_jvmstatic(false),
use_flexbuffers(false),
strict_json(false),
@@ -685,8 +685,8 @@ struct IDLOptions {
lang_to_generate(0),
set_empty_strings_to_null(true),
set_empty_vectors_to_null(true) {}
-};
-
+};
+
// This encapsulates where the parser is in the current source file.
struct ParserState {
ParserState()
@@ -726,55 +726,55 @@ struct ParserState {
std::vector<std::string> doc_comment_;
};
-// A way to make error propagation less error prone by requiring values to be
-// checked.
-// Once you create a value of this type you must either:
-// - Call Check() on it.
-// - Copy or assign it to another value.
-// Failure to do so leads to an assert.
-// This guarantees that this as return value cannot be ignored.
-class CheckedError {
- public:
- explicit CheckedError(bool error)
+// A way to make error propagation less error prone by requiring values to be
+// checked.
+// Once you create a value of this type you must either:
+// - Call Check() on it.
+// - Copy or assign it to another value.
+// Failure to do so leads to an assert.
+// This guarantees that this as return value cannot be ignored.
+class CheckedError {
+ public:
+ explicit CheckedError(bool error)
: is_error_(error), has_been_checked_(false) {}
-
- CheckedError &operator=(const CheckedError &other) {
- is_error_ = other.is_error_;
- has_been_checked_ = false;
- other.has_been_checked_ = true;
- return *this;
- }
-
- CheckedError(const CheckedError &other) {
- *this = other; // Use assignment operator.
- }
-
+
+ CheckedError &operator=(const CheckedError &other) {
+ is_error_ = other.is_error_;
+ has_been_checked_ = false;
+ other.has_been_checked_ = true;
+ return *this;
+ }
+
+ CheckedError(const CheckedError &other) {
+ *this = other; // Use assignment operator.
+ }
+
~CheckedError() { FLATBUFFERS_ASSERT(has_been_checked_); }
-
+
bool Check() {
has_been_checked_ = true;
return is_error_;
}
-
- private:
- bool is_error_;
- mutable bool has_been_checked_;
-};
-
-// Additionally, in GCC we can get these errors statically, for additional
-// assurance:
+
+ private:
+ bool is_error_;
+ mutable bool has_been_checked_;
+};
+
+// Additionally, in GCC we can get these errors statically, for additional
+// assurance:
// clang-format off
-#ifdef __GNUC__
-#define FLATBUFFERS_CHECKED_ERROR CheckedError \
- __attribute__((warn_unused_result))
-#else
-#define FLATBUFFERS_CHECKED_ERROR CheckedError
-#endif
+#ifdef __GNUC__
+#define FLATBUFFERS_CHECKED_ERROR CheckedError \
+ __attribute__((warn_unused_result))
+#else
+#define FLATBUFFERS_CHECKED_ERROR CheckedError
+#endif
// clang-format on
-
+
class Parser : public ParserState {
- public:
- explicit Parser(const IDLOptions &options = IDLOptions())
+ public:
+ explicit Parser(const IDLOptions &options = IDLOptions())
: current_namespace_(nullptr),
empty_namespace_(nullptr),
flex_builder_(256, flexbuffers::BUILDER_FLAG_SHARE_ALL),
@@ -815,45 +815,45 @@ class Parser : public ParserState {
known_attributes_["native_default"] = true;
known_attributes_["flexbuffer"] = true;
known_attributes_["private"] = true;
- }
-
- ~Parser() {
- for (auto it = namespaces_.begin(); it != namespaces_.end(); ++it) {
- delete *it;
- }
- }
-
- // Parse the string containing either schema or JSON data, which will
- // populate the SymbolTable's or the FlatBufferBuilder above.
- // include_paths is used to resolve any include statements, and typically
- // should at least include the project path (where you loaded source_ from).
- // include_paths must be nullptr terminated if specified.
- // If include_paths is nullptr, it will attempt to load from the current
- // directory.
- // If the source was loaded from a file and isn't an include file,
- // supply its name in source_filename.
+ }
+
+ ~Parser() {
+ for (auto it = namespaces_.begin(); it != namespaces_.end(); ++it) {
+ delete *it;
+ }
+ }
+
+ // Parse the string containing either schema or JSON data, which will
+ // populate the SymbolTable's or the FlatBufferBuilder above.
+ // include_paths is used to resolve any include statements, and typically
+ // should at least include the project path (where you loaded source_ from).
+ // include_paths must be nullptr terminated if specified.
+ // If include_paths is nullptr, it will attempt to load from the current
+ // directory.
+ // If the source was loaded from a file and isn't an include file,
+ // supply its name in source_filename.
// All paths specified in this call must be in posix format, if you accept
// paths from user input, please call PosixPath on them first.
- bool Parse(const char *_source, const char **include_paths = nullptr,
- const char *source_filename = nullptr);
-
+ bool Parse(const char *_source, const char **include_paths = nullptr,
+ const char *source_filename = nullptr);
+
bool ParseJson(const char *json, const char *json_filename = nullptr);
- // Set the root type. May override the one set in the schema.
- bool SetRootType(const char *name);
-
- // Mark all definitions as already having code generated.
- void MarkGenerated();
-
- // Get the files recursively included by the given file. The returned
- // container will have at least the given file.
- std::set<std::string> GetIncludedFilesRecursive(
- const std::string &file_name) const;
-
- // Fills builder_ with a binary version of the schema parsed.
- // See reflection/reflection.fbs
- void Serialize();
-
+ // Set the root type. May override the one set in the schema.
+ bool SetRootType(const char *name);
+
+ // Mark all definitions as already having code generated.
+ void MarkGenerated();
+
+ // Get the files recursively included by the given file. The returned
+ // container will have at least the given file.
+ std::set<std::string> GetIncludedFilesRecursive(
+ const std::string &file_name) const;
+
+ // Fills builder_ with a binary version of the schema parsed.
+ // See reflection/reflection.fbs
+ void Serialize();
+
// Deserialize a schema buffer
bool Deserialize(const uint8_t *buf, const size_t size);
@@ -866,7 +866,7 @@ class Parser : public ParserState {
// Checks that the schema represented by this parser is a safe evolution
// of the schema provided. Returns non-empty error on any problems.
std::string ConformTo(const Parser &base);
-
+
// Similar to Parse(), but now only accepts JSON to be parsed into a
// FlexBuffer.
bool ParseFlexBuffer(const char *source, const char *source_filename,
@@ -890,24 +890,24 @@ class Parser : public ParserState {
void Message(const std::string &msg);
void Warning(const std::string &msg);
FLATBUFFERS_CHECKED_ERROR ParseHexNum(int nibbles, uint64_t *val);
- FLATBUFFERS_CHECKED_ERROR Next();
- FLATBUFFERS_CHECKED_ERROR SkipByteOrderMark();
+ FLATBUFFERS_CHECKED_ERROR Next();
+ FLATBUFFERS_CHECKED_ERROR SkipByteOrderMark();
bool Is(int t) const;
bool IsIdent(const char *id) const;
- FLATBUFFERS_CHECKED_ERROR Expect(int t);
+ FLATBUFFERS_CHECKED_ERROR Expect(int t);
std::string TokenToStringId(int t) const;
- EnumDef *LookupEnum(const std::string &id);
- FLATBUFFERS_CHECKED_ERROR ParseNamespacing(std::string *id,
- std::string *last);
- FLATBUFFERS_CHECKED_ERROR ParseTypeIdent(Type &type);
- FLATBUFFERS_CHECKED_ERROR ParseType(Type &type);
- FLATBUFFERS_CHECKED_ERROR AddField(StructDef &struct_def,
- const std::string &name, const Type &type,
- FieldDef **dest);
- FLATBUFFERS_CHECKED_ERROR ParseField(StructDef &struct_def);
+ EnumDef *LookupEnum(const std::string &id);
+ FLATBUFFERS_CHECKED_ERROR ParseNamespacing(std::string *id,
+ std::string *last);
+ FLATBUFFERS_CHECKED_ERROR ParseTypeIdent(Type &type);
+ FLATBUFFERS_CHECKED_ERROR ParseType(Type &type);
+ FLATBUFFERS_CHECKED_ERROR AddField(StructDef &struct_def,
+ const std::string &name, const Type &type,
+ FieldDef **dest);
+ FLATBUFFERS_CHECKED_ERROR ParseField(StructDef &struct_def);
FLATBUFFERS_CHECKED_ERROR ParseString(Value &val, bool use_string_pooling);
FLATBUFFERS_CHECKED_ERROR ParseComma();
- FLATBUFFERS_CHECKED_ERROR ParseAnyValue(Value &val, FieldDef *field,
+ FLATBUFFERS_CHECKED_ERROR ParseAnyValue(Value &val, FieldDef *field,
size_t parent_fieldn,
const StructDef *parent_struct_def,
uoffset_t count,
@@ -916,9 +916,9 @@ class Parser : public ParserState {
FLATBUFFERS_CHECKED_ERROR ParseTableDelimiters(size_t &fieldn,
const StructDef *struct_def,
F body);
- FLATBUFFERS_CHECKED_ERROR ParseTable(const StructDef &struct_def,
- std::string *value, uoffset_t *ovalue);
- void SerializeStruct(const StructDef &struct_def, const Value &val);
+ FLATBUFFERS_CHECKED_ERROR ParseTable(const StructDef &struct_def,
+ std::string *value, uoffset_t *ovalue);
+ void SerializeStruct(const StructDef &struct_def, const Value &val);
void SerializeStruct(FlatBufferBuilder &builder, const StructDef &struct_def,
const Value &val);
template<typename F>
@@ -940,25 +940,25 @@ class Parser : public ParserState {
FLATBUFFERS_CHECKED_ERROR ParseFunction(const std::string *name, Value &e);
FLATBUFFERS_CHECKED_ERROR ParseEnumFromString(const Type &type,
std::string *result);
- StructDef *LookupCreateStruct(const std::string &name,
- bool create_if_new = true,
- bool definition = false);
- FLATBUFFERS_CHECKED_ERROR ParseEnum(bool is_union, EnumDef **dest);
- FLATBUFFERS_CHECKED_ERROR ParseNamespace();
- FLATBUFFERS_CHECKED_ERROR StartStruct(const std::string &name,
- StructDef **dest);
+ StructDef *LookupCreateStruct(const std::string &name,
+ bool create_if_new = true,
+ bool definition = false);
+ FLATBUFFERS_CHECKED_ERROR ParseEnum(bool is_union, EnumDef **dest);
+ FLATBUFFERS_CHECKED_ERROR ParseNamespace();
+ FLATBUFFERS_CHECKED_ERROR StartStruct(const std::string &name,
+ StructDef **dest);
FLATBUFFERS_CHECKED_ERROR StartEnum(const std::string &name, bool is_union,
EnumDef **dest);
- FLATBUFFERS_CHECKED_ERROR ParseDecl();
+ FLATBUFFERS_CHECKED_ERROR ParseDecl();
FLATBUFFERS_CHECKED_ERROR ParseService();
- FLATBUFFERS_CHECKED_ERROR ParseProtoFields(StructDef *struct_def,
- bool isextend, bool inside_oneof);
- FLATBUFFERS_CHECKED_ERROR ParseProtoOption();
- FLATBUFFERS_CHECKED_ERROR ParseProtoKey();
- FLATBUFFERS_CHECKED_ERROR ParseProtoDecl();
- FLATBUFFERS_CHECKED_ERROR ParseProtoCurliesOrIdent();
- FLATBUFFERS_CHECKED_ERROR ParseTypeFromProtoType(Type *type);
- FLATBUFFERS_CHECKED_ERROR SkipAnyJsonValue();
+ FLATBUFFERS_CHECKED_ERROR ParseProtoFields(StructDef *struct_def,
+ bool isextend, bool inside_oneof);
+ FLATBUFFERS_CHECKED_ERROR ParseProtoOption();
+ FLATBUFFERS_CHECKED_ERROR ParseProtoKey();
+ FLATBUFFERS_CHECKED_ERROR ParseProtoDecl();
+ FLATBUFFERS_CHECKED_ERROR ParseProtoCurliesOrIdent();
+ FLATBUFFERS_CHECKED_ERROR ParseTypeFromProtoType(Type *type);
+ FLATBUFFERS_CHECKED_ERROR SkipAnyJsonValue();
FLATBUFFERS_CHECKED_ERROR ParseFlexBufferNumericConstant(
flexbuffers::Builder *builder);
FLATBUFFERS_CHECKED_ERROR ParseFlexBufferValue(flexbuffers::Builder *builder);
@@ -973,11 +973,11 @@ class Parser : public ParserState {
const char *include_filename);
FLATBUFFERS_CHECKED_ERROR DoParseJson();
FLATBUFFERS_CHECKED_ERROR CheckClash(std::vector<FieldDef *> &fields,
- StructDef *struct_def,
+ StructDef *struct_def,
const char *suffix, BaseType baseType);
FLATBUFFERS_CHECKED_ERROR ParseAlignAttribute(
const std::string &align_constant, size_t min_align, size_t *align);
-
+
bool SupportsAdvancedUnionFeatures() const;
bool SupportsAdvancedArrayFeatures() const;
bool SupportsOptionalScalars() const;
@@ -987,82 +987,82 @@ class Parser : public ParserState {
FLATBUFFERS_CHECKED_ERROR RecurseError();
template<typename F> CheckedError Recurse(F f);
- public:
+ public:
SymbolTable<Type> types_;
- SymbolTable<StructDef> structs_;
- SymbolTable<EnumDef> enums_;
+ SymbolTable<StructDef> structs_;
+ SymbolTable<EnumDef> enums_;
SymbolTable<ServiceDef> services_;
- std::vector<Namespace *> namespaces_;
+ std::vector<Namespace *> namespaces_;
Namespace *current_namespace_;
Namespace *empty_namespace_;
std::string error_; // User readable error_ if Parse() == false
-
- FlatBufferBuilder builder_; // any data contained in the file
+
+ FlatBufferBuilder builder_; // any data contained in the file
flexbuffers::Builder flex_builder_;
flexbuffers::Reference flex_root_;
- StructDef *root_struct_def_;
- std::string file_identifier_;
- std::string file_extension_;
-
+ StructDef *root_struct_def_;
+ std::string file_identifier_;
+ std::string file_extension_;
+
std::map<uint64_t, std::string> included_files_;
- std::map<std::string, std::set<std::string>> files_included_per_file_;
+ std::map<std::string, std::set<std::string>> files_included_per_file_;
std::vector<std::string> native_included_files_;
-
+
std::map<std::string, bool> known_attributes_;
- IDLOptions opts;
+ IDLOptions opts;
bool uses_flexbuffers_;
-
+
uint64_t advanced_features_;
- private:
+ private:
const char *source_;
- std::string file_being_parsed_;
-
- std::vector<std::pair<Value, FieldDef *>> field_stack_;
-
+ std::string file_being_parsed_;
+
+ std::vector<std::pair<Value, FieldDef *>> field_stack_;
+
int anonymous_counter_;
int parse_depth_counter_; // stack-overflow guard
-};
-
-// Utility functions for multiple generators:
-
-extern std::string MakeCamel(const std::string &in, bool first = true);
-
+};
+
+// Utility functions for multiple generators:
+
+extern std::string MakeCamel(const std::string &in, bool first = true);
+
extern std::string MakeScreamingCamel(const std::string &in);
-// Generate text (JSON) from a given FlatBuffer, and a given Parser
-// object that has been populated with the corresponding schema.
-// If ident_step is 0, no indentation will be generated. Additionally,
-// if it is less than 0, no linefeeds will be generated either.
-// See idl_gen_text.cpp.
-// strict_json adds "quotes" around field names if true.
+// Generate text (JSON) from a given FlatBuffer, and a given Parser
+// object that has been populated with the corresponding schema.
+// If ident_step is 0, no indentation will be generated. Additionally,
+// if it is less than 0, no linefeeds will be generated either.
+// See idl_gen_text.cpp.
+// strict_json adds "quotes" around field names if true.
// If the flatbuffer cannot be encoded in JSON (e.g., it contains non-UTF-8
// byte arrays in String values), returns false.
extern bool GenerateTextFromTable(const Parser &parser, const void *table,
const std::string &tablename,
std::string *text);
extern bool GenerateText(const Parser &parser, const void *flatbuffer,
- std::string *text);
+ std::string *text);
extern bool GenerateTextFile(const Parser &parser, const std::string &path,
- const std::string &file_name);
-
+ const std::string &file_name);
+
// Generate Json schema to string
// See idl_gen_json_schema.cpp.
extern bool GenerateJsonSchema(const Parser &parser, std::string *json);
-// Generate binary files from a given FlatBuffer, and a given Parser
-// object that has been populated with the corresponding schema.
+// Generate binary files from a given FlatBuffer, and a given Parser
+// object that has been populated with the corresponding schema.
// See code_generators.cpp.
extern bool GenerateBinary(const Parser &parser, const std::string &path,
- const std::string &file_name);
-
-// Generate a C++ header from the definitions in the Parser object.
-// See idl_gen_cpp.
+ const std::string &file_name);
+
+// Generate a C++ header from the definitions in the Parser object.
+// See idl_gen_cpp.
extern bool GenerateCPP(const Parser &parser, const std::string &path,
- const std::string &file_name);
-
+ const std::string &file_name);
+
// Generate C# files from the definitions in the Parser object.
// See idl_gen_csharp.cpp.
extern bool GenerateCSharp(const Parser &parser, const std::string &path,
@@ -1075,27 +1075,27 @@ extern bool GenerateDart(const Parser &parser, const std::string &path,
// See idl_gen_java.cpp.
extern bool GenerateJava(const Parser &parser, const std::string &path,
const std::string &file_name);
-
+
// Generate JavaScript or TypeScript code from the definitions in the Parser
// object. See idl_gen_js.
extern bool GenerateTS(const Parser &parser, const std::string &path,
const std::string &file_name);
-// Generate Go files from the definitions in the Parser object.
-// See idl_gen_go.cpp.
+// Generate Go files from the definitions in the Parser object.
+// See idl_gen_go.cpp.
extern bool GenerateGo(const Parser &parser, const std::string &path,
- const std::string &file_name);
-
-// Generate Php code from the definitions in the Parser object.
-// See idl_gen_php.
+ const std::string &file_name);
+
+// Generate Php code from the definitions in the Parser object.
+// See idl_gen_php.
extern bool GeneratePhp(const Parser &parser, const std::string &path,
const std::string &file_name);
-
-// Generate Python files from the definitions in the Parser object.
-// See idl_gen_python.cpp.
+
+// Generate Python files from the definitions in the Parser object.
+// See idl_gen_python.cpp.
extern bool GeneratePython(const Parser &parser, const std::string &path,
- const std::string &file_name);
-
+ const std::string &file_name);
+
// Generate Lobster files from the definitions in the Parser object.
// See idl_gen_lobster.cpp.
extern bool GenerateLobster(const Parser &parser, const std::string &path,
@@ -1117,20 +1117,20 @@ extern bool GenerateJsonSchema(const Parser &parser, const std::string &path,
const std::string &file_name);
extern bool GenerateKotlin(const Parser &parser, const std::string &path,
- const std::string &file_name);
-
+ const std::string &file_name);
+
// Generate Swift classes.
// See idl_gen_swift.cpp
extern bool GenerateSwift(const Parser &parser, const std::string &path,
const std::string &file_name);
-
-// Generate a schema file from the internal representation, useful after
-// parsing a .proto schema.
-extern std::string GenerateFBS(const Parser &parser,
- const std::string &file_name);
+
+// Generate a schema file from the internal representation, useful after
+// parsing a .proto schema.
+extern std::string GenerateFBS(const Parser &parser,
+ const std::string &file_name);
extern bool GenerateFBS(const Parser &parser, const std::string &path,
- const std::string &file_name);
-
+ const std::string &file_name);
+
// Generate a C++ header for reading with templated file iterator from
// the definitions in the Parser object.
// See idl_gen_cpp_yandex_maps_iter.cpp.
@@ -1144,12 +1144,12 @@ extern bool GenerateCPPYandexMapsIter(const Parser &parser,
// See idl_gen_ts.cpp.
extern std::string TSMakeRule(const Parser &parser, const std::string &path,
const std::string &file_name);
-
-// Generate a make rule for the generated C++ header.
-// See idl_gen_cpp.cpp.
+
+// Generate a make rule for the generated C++ header.
+// See idl_gen_cpp.cpp.
extern std::string CPPMakeRule(const Parser &parser, const std::string &path,
- const std::string &file_name);
-
+ const std::string &file_name);
+
// Generate a make rule for the generated Dart code
// see idl_gen_dart.cpp
extern std::string DartMakeRule(const Parser &parser, const std::string &path,
@@ -1165,17 +1165,17 @@ extern std::string RustMakeRule(const Parser &parser, const std::string &path,
extern std::string JavaCSharpMakeRule(const Parser &parser,
const std::string &path,
const std::string &file_name);
-
-// Generate a make rule for the generated text (JSON) files.
-// See idl_gen_text.cpp.
+
+// Generate a make rule for the generated text (JSON) files.
+// See idl_gen_text.cpp.
extern std::string TextMakeRule(const Parser &parser, const std::string &path,
- const std::string &file_names);
-
-// Generate a make rule for the generated binary files.
+ const std::string &file_names);
+
+// Generate a make rule for the generated binary files.
// See code_generators.cpp.
extern std::string BinaryMakeRule(const Parser &parser, const std::string &path,
- const std::string &file_name);
-
+ const std::string &file_name);
+
// Generate GRPC Cpp interfaces.
// See idl_gen_grpc.cpp.
bool GenerateCppGRPC(const Parser &parser, const std::string &path,
@@ -1203,6 +1203,6 @@ extern bool GenerateSwiftGRPC(const Parser &parser, const std::string &path,
extern bool GenerateTSGRPC(const Parser &parser, const std::string &path,
const std::string &file_name);
-} // namespace flatbuffers
-
-#endif // FLATBUFFERS_IDL_H_
+} // namespace flatbuffers
+
+#endif // FLATBUFFERS_IDL_H_
diff --git a/contrib/libs/flatbuffers/include/flatbuffers/reflection.h b/contrib/libs/flatbuffers/include/flatbuffers/reflection.h
index 1a3e767d2e..d268a3ffea 100644
--- a/contrib/libs/flatbuffers/include/flatbuffers/reflection.h
+++ b/contrib/libs/flatbuffers/include/flatbuffers/reflection.h
@@ -1,35 +1,35 @@
-/*
- * Copyright 2015 Google Inc. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef FLATBUFFERS_REFLECTION_H_
-#define FLATBUFFERS_REFLECTION_H_
-
-// This is somewhat of a circular dependency because flatc (and thus this
-// file) is needed to generate this header in the first place.
-// Should normally not be a problem since it can be generated by the
-// previous version of flatc whenever this code needs to change.
-// See reflection/generate_code.sh
+/*
+ * Copyright 2015 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FLATBUFFERS_REFLECTION_H_
+#define FLATBUFFERS_REFLECTION_H_
+
+// This is somewhat of a circular dependency because flatc (and thus this
+// file) is needed to generate this header in the first place.
+// Should normally not be a problem since it can be generated by the
+// previous version of flatc whenever this code needs to change.
+// See reflection/generate_code.sh
#include "reflection_generated.h"
-
-// Helper functionality for reflection.
-
-namespace flatbuffers {
-
-// ------------------------- GETTERS -------------------------
-
+
+// Helper functionality for reflection.
+
+namespace flatbuffers {
+
+// ------------------------- GETTERS -------------------------
+
inline bool IsScalar(reflection::BaseType t) {
return t >= reflection::UType && t <= reflection::Double;
}
@@ -43,9 +43,9 @@ inline bool IsLong(reflection::BaseType t) {
return t == reflection::Long || t == reflection::ULong;
}
-// Size of a basic type, don't use with structs.
-inline size_t GetTypeSize(reflection::BaseType base_type) {
- // This needs to correspond to the BaseType enum.
+// Size of a basic type, don't use with structs.
+inline size_t GetTypeSize(reflection::BaseType base_type) {
+ // This needs to correspond to the BaseType enum.
static size_t sizes[] = {
0, // None
1, // UType
@@ -72,29 +72,29 @@ inline size_t GetTypeSize(reflection::BaseType base_type) {
static_assert(sizeof(sizes) / sizeof(size_t) == reflection::MaxBaseType + 1,
"Size of sizes[] array does not match the count of BaseType "
"enum values.");
- return sizes[base_type];
-}
-
-// Same as above, but now correctly returns the size of a struct if
-// the field (or vector element) is a struct.
+ return sizes[base_type];
+}
+
+// Same as above, but now correctly returns the size of a struct if
+// the field (or vector element) is a struct.
inline size_t GetTypeSizeInline(reflection::BaseType base_type, int type_index,
- const reflection::Schema &schema) {
- if (base_type == reflection::Obj &&
- schema.objects()->Get(type_index)->is_struct()) {
- return schema.objects()->Get(type_index)->bytesize();
- } else {
- return GetTypeSize(base_type);
- }
-}
-
-// Get the root, regardless of what type it is.
-inline Table *GetAnyRoot(uint8_t *flatbuf) {
- return GetMutableRoot<Table>(flatbuf);
-}
-inline const Table *GetAnyRoot(const uint8_t *flatbuf) {
- return GetRoot<Table>(flatbuf);
-}
-
+ const reflection::Schema &schema) {
+ if (base_type == reflection::Obj &&
+ schema.objects()->Get(type_index)->is_struct()) {
+ return schema.objects()->Get(type_index)->bytesize();
+ } else {
+ return GetTypeSize(base_type);
+ }
+}
+
+// Get the root, regardless of what type it is.
+inline Table *GetAnyRoot(uint8_t *flatbuf) {
+ return GetMutableRoot<Table>(flatbuf);
+}
+inline const Table *GetAnyRoot(const uint8_t *flatbuf) {
+ return GetRoot<Table>(flatbuf);
+}
+
// Get a field's default, if you know it's an integer, and its exact type.
template<typename T> T GetFieldDefaultI(const reflection::Field &field) {
FLATBUFFERS_ASSERT(sizeof(T) == GetTypeSize(field.type()->base_type()));
@@ -107,52 +107,52 @@ template<typename T> T GetFieldDefaultF(const reflection::Field &field) {
return static_cast<T>(field.default_real());
}
-// Get a field, if you know it's an integer, and its exact type.
+// Get a field, if you know it's an integer, and its exact type.
template<typename T>
T GetFieldI(const Table &table, const reflection::Field &field) {
FLATBUFFERS_ASSERT(sizeof(T) == GetTypeSize(field.type()->base_type()));
- return table.GetField<T>(field.offset(),
- static_cast<T>(field.default_integer()));
-}
-
-// Get a field, if you know it's floating point and its exact type.
+ return table.GetField<T>(field.offset(),
+ static_cast<T>(field.default_integer()));
+}
+
+// Get a field, if you know it's floating point and its exact type.
template<typename T>
T GetFieldF(const Table &table, const reflection::Field &field) {
FLATBUFFERS_ASSERT(sizeof(T) == GetTypeSize(field.type()->base_type()));
- return table.GetField<T>(field.offset(),
- static_cast<T>(field.default_real()));
-}
-
-// Get a field, if you know it's a string.
-inline const String *GetFieldS(const Table &table,
- const reflection::Field &field) {
+ return table.GetField<T>(field.offset(),
+ static_cast<T>(field.default_real()));
+}
+
+// Get a field, if you know it's a string.
+inline const String *GetFieldS(const Table &table,
+ const reflection::Field &field) {
FLATBUFFERS_ASSERT(field.type()->base_type() == reflection::String);
- return table.GetPointer<const String *>(field.offset());
-}
-
-// Get a field, if you know it's a vector.
+ return table.GetPointer<const String *>(field.offset());
+}
+
+// Get a field, if you know it's a vector.
template<typename T>
Vector<T> *GetFieldV(const Table &table, const reflection::Field &field) {
FLATBUFFERS_ASSERT(field.type()->base_type() == reflection::Vector &&
sizeof(T) == GetTypeSize(field.type()->element()));
- return table.GetPointer<Vector<T> *>(field.offset());
-}
-
-// Get a field, if you know it's a vector, generically.
-// To actually access elements, use the return value together with
-// field.type()->element() in any of GetAnyVectorElemI below etc.
-inline VectorOfAny *GetFieldAnyV(const Table &table,
- const reflection::Field &field) {
- return table.GetPointer<VectorOfAny *>(field.offset());
-}
-
-// Get a field, if you know it's a table.
+ return table.GetPointer<Vector<T> *>(field.offset());
+}
+
+// Get a field, if you know it's a vector, generically.
+// To actually access elements, use the return value together with
+// field.type()->element() in any of GetAnyVectorElemI below etc.
+inline VectorOfAny *GetFieldAnyV(const Table &table,
+ const reflection::Field &field) {
+ return table.GetPointer<VectorOfAny *>(field.offset());
+}
+
+// Get a field, if you know it's a table.
inline Table *GetFieldT(const Table &table, const reflection::Field &field) {
FLATBUFFERS_ASSERT(field.type()->base_type() == reflection::Obj ||
field.type()->base_type() == reflection::Union);
- return table.GetPointer<Table *>(field.offset());
-}
-
+ return table.GetPointer<Table *>(field.offset());
+}
+
// Get a field, if you know it's a struct.
inline const Struct *GetFieldStruct(const Table &table,
const reflection::Field &field) {
@@ -169,119 +169,119 @@ inline const Struct *GetFieldStruct(const Struct &structure,
return structure.GetStruct<const Struct *>(field.offset());
}
-// Raw helper functions used below: get any value in memory as a 64bit int, a
-// double or a string.
-// All scalars get static_cast to an int64_t, strings use strtoull, every other
-// data type returns 0.
-int64_t GetAnyValueI(reflection::BaseType type, const uint8_t *data);
-// All scalars static cast to double, strings use strtod, every other data
-// type is 0.0.
-double GetAnyValueF(reflection::BaseType type, const uint8_t *data);
-// All scalars converted using stringstream, strings as-is, and all other
-// data types provide some level of debug-pretty-printing.
-std::string GetAnyValueS(reflection::BaseType type, const uint8_t *data,
+// Raw helper functions used below: get any value in memory as a 64bit int, a
+// double or a string.
+// All scalars get static_cast to an int64_t, strings use strtoull, every other
+// data type returns 0.
+int64_t GetAnyValueI(reflection::BaseType type, const uint8_t *data);
+// All scalars static cast to double, strings use strtod, every other data
+// type is 0.0.
+double GetAnyValueF(reflection::BaseType type, const uint8_t *data);
+// All scalars converted using stringstream, strings as-is, and all other
+// data types provide some level of debug-pretty-printing.
+std::string GetAnyValueS(reflection::BaseType type, const uint8_t *data,
const reflection::Schema *schema, int type_index);
-
-// Get any table field as a 64bit int, regardless of what type it is.
-inline int64_t GetAnyFieldI(const Table &table,
- const reflection::Field &field) {
- auto field_ptr = table.GetAddressOf(field.offset());
- return field_ptr ? GetAnyValueI(field.type()->base_type(), field_ptr)
- : field.default_integer();
-}
-
-// Get any table field as a double, regardless of what type it is.
+
+// Get any table field as a 64bit int, regardless of what type it is.
+inline int64_t GetAnyFieldI(const Table &table,
+ const reflection::Field &field) {
+ auto field_ptr = table.GetAddressOf(field.offset());
+ return field_ptr ? GetAnyValueI(field.type()->base_type(), field_ptr)
+ : field.default_integer();
+}
+
+// Get any table field as a double, regardless of what type it is.
inline double GetAnyFieldF(const Table &table, const reflection::Field &field) {
- auto field_ptr = table.GetAddressOf(field.offset());
- return field_ptr ? GetAnyValueF(field.type()->base_type(), field_ptr)
- : field.default_real();
-}
-
-// Get any table field as a string, regardless of what type it is.
-// You may pass nullptr for the schema if you don't care to have fields that
-// are of table type pretty-printed.
-inline std::string GetAnyFieldS(const Table &table,
- const reflection::Field &field,
- const reflection::Schema *schema) {
- auto field_ptr = table.GetAddressOf(field.offset());
- return field_ptr ? GetAnyValueS(field.type()->base_type(), field_ptr, schema,
- field.type()->index())
- : "";
-}
-
-// Get any struct field as a 64bit int, regardless of what type it is.
+ auto field_ptr = table.GetAddressOf(field.offset());
+ return field_ptr ? GetAnyValueF(field.type()->base_type(), field_ptr)
+ : field.default_real();
+}
+
+// Get any table field as a string, regardless of what type it is.
+// You may pass nullptr for the schema if you don't care to have fields that
+// are of table type pretty-printed.
+inline std::string GetAnyFieldS(const Table &table,
+ const reflection::Field &field,
+ const reflection::Schema *schema) {
+ auto field_ptr = table.GetAddressOf(field.offset());
+ return field_ptr ? GetAnyValueS(field.type()->base_type(), field_ptr, schema,
+ field.type()->index())
+ : "";
+}
+
+// Get any struct field as a 64bit int, regardless of what type it is.
inline int64_t GetAnyFieldI(const Struct &st, const reflection::Field &field) {
- return GetAnyValueI(field.type()->base_type(),
- st.GetAddressOf(field.offset()));
-}
-
-// Get any struct field as a double, regardless of what type it is.
+ return GetAnyValueI(field.type()->base_type(),
+ st.GetAddressOf(field.offset()));
+}
+
+// Get any struct field as a double, regardless of what type it is.
inline double GetAnyFieldF(const Struct &st, const reflection::Field &field) {
- return GetAnyValueF(field.type()->base_type(),
- st.GetAddressOf(field.offset()));
-}
-
-// Get any struct field as a string, regardless of what type it is.
-inline std::string GetAnyFieldS(const Struct &st,
- const reflection::Field &field) {
- return GetAnyValueS(field.type()->base_type(),
- st.GetAddressOf(field.offset()), nullptr, -1);
-}
-
-// Get any vector element as a 64bit int, regardless of what type it is.
-inline int64_t GetAnyVectorElemI(const VectorOfAny *vec,
- reflection::BaseType elem_type, size_t i) {
- return GetAnyValueI(elem_type, vec->Data() + GetTypeSize(elem_type) * i);
-}
-
-// Get any vector element as a double, regardless of what type it is.
-inline double GetAnyVectorElemF(const VectorOfAny *vec,
- reflection::BaseType elem_type, size_t i) {
- return GetAnyValueF(elem_type, vec->Data() + GetTypeSize(elem_type) * i);
-}
-
-// Get any vector element as a string, regardless of what type it is.
-inline std::string GetAnyVectorElemS(const VectorOfAny *vec,
- reflection::BaseType elem_type, size_t i) {
- return GetAnyValueS(elem_type, vec->Data() + GetTypeSize(elem_type) * i,
- nullptr, -1);
-}
-
-// Get a vector element that's a table/string/vector from a generic vector.
-// Pass Table/String/VectorOfAny as template parameter.
-// Warning: does no typechecking.
+ return GetAnyValueF(field.type()->base_type(),
+ st.GetAddressOf(field.offset()));
+}
+
+// Get any struct field as a string, regardless of what type it is.
+inline std::string GetAnyFieldS(const Struct &st,
+ const reflection::Field &field) {
+ return GetAnyValueS(field.type()->base_type(),
+ st.GetAddressOf(field.offset()), nullptr, -1);
+}
+
+// Get any vector element as a 64bit int, regardless of what type it is.
+inline int64_t GetAnyVectorElemI(const VectorOfAny *vec,
+ reflection::BaseType elem_type, size_t i) {
+ return GetAnyValueI(elem_type, vec->Data() + GetTypeSize(elem_type) * i);
+}
+
+// Get any vector element as a double, regardless of what type it is.
+inline double GetAnyVectorElemF(const VectorOfAny *vec,
+ reflection::BaseType elem_type, size_t i) {
+ return GetAnyValueF(elem_type, vec->Data() + GetTypeSize(elem_type) * i);
+}
+
+// Get any vector element as a string, regardless of what type it is.
+inline std::string GetAnyVectorElemS(const VectorOfAny *vec,
+ reflection::BaseType elem_type, size_t i) {
+ return GetAnyValueS(elem_type, vec->Data() + GetTypeSize(elem_type) * i,
+ nullptr, -1);
+}
+
+// Get a vector element that's a table/string/vector from a generic vector.
+// Pass Table/String/VectorOfAny as template parameter.
+// Warning: does no typechecking.
template<typename T>
T *GetAnyVectorElemPointer(const VectorOfAny *vec, size_t i) {
- auto elem_ptr = vec->Data() + sizeof(uoffset_t) * i;
+ auto elem_ptr = vec->Data() + sizeof(uoffset_t) * i;
return reinterpret_cast<T *>(elem_ptr + ReadScalar<uoffset_t>(elem_ptr));
-}
-
-// Get the inline-address of a vector element. Useful for Structs (pass Struct
-// as template arg), or being able to address a range of scalars in-line.
-// Get elem_size from GetTypeSizeInline().
-// Note: little-endian data on all platforms, use EndianScalar() instead of
-// raw pointer access with scalars).
+}
+
+// Get the inline-address of a vector element. Useful for Structs (pass Struct
+// as template arg), or being able to address a range of scalars in-line.
+// Get elem_size from GetTypeSizeInline().
+// Note: little-endian data on all platforms, use EndianScalar() instead of
+// raw pointer access with scalars).
template<typename T>
T *GetAnyVectorElemAddressOf(const VectorOfAny *vec, size_t i,
size_t elem_size) {
return reinterpret_cast<T *>(vec->Data() + elem_size * i);
-}
-
-// Similarly, for elements of tables.
+}
+
+// Similarly, for elements of tables.
template<typename T>
T *GetAnyFieldAddressOf(const Table &table, const reflection::Field &field) {
return reinterpret_cast<T *>(table.GetAddressOf(field.offset()));
-}
-
-// Similarly, for elements of structs.
+}
+
+// Similarly, for elements of structs.
template<typename T>
T *GetAnyFieldAddressOf(const Struct &st, const reflection::Field &field) {
return reinterpret_cast<T *>(st.GetAddressOf(field.offset()));
-}
-
-// ------------------------- SETTERS -------------------------
-
-// Set any scalar field, if you know its exact type.
+}
+
+// ------------------------- SETTERS -------------------------
+
+// Set any scalar field, if you know its exact type.
template<typename T>
bool SetField(Table *table, const reflection::Field &field, T val) {
reflection::BaseType type = field.type()->base_type();
@@ -295,200 +295,200 @@ bool SetField(Table *table, const reflection::Field &field, T val) {
def = GetFieldDefaultF<T>(field);
}
return table->SetField(field.offset(), val, def);
-}
-
-// Raw helper functions used below: set any value in memory as a 64bit int, a
-// double or a string.
-// These work for all scalar values, but do nothing for other data types.
-// To set a string, see SetString below.
-void SetAnyValueI(reflection::BaseType type, uint8_t *data, int64_t val);
-void SetAnyValueF(reflection::BaseType type, uint8_t *data, double val);
-void SetAnyValueS(reflection::BaseType type, uint8_t *data, const char *val);
-
-// Set any table field as a 64bit int, regardless of type what it is.
-inline bool SetAnyFieldI(Table *table, const reflection::Field &field,
- int64_t val) {
- auto field_ptr = table->GetAddressOf(field.offset());
+}
+
+// Raw helper functions used below: set any value in memory as a 64bit int, a
+// double or a string.
+// These work for all scalar values, but do nothing for other data types.
+// To set a string, see SetString below.
+void SetAnyValueI(reflection::BaseType type, uint8_t *data, int64_t val);
+void SetAnyValueF(reflection::BaseType type, uint8_t *data, double val);
+void SetAnyValueS(reflection::BaseType type, uint8_t *data, const char *val);
+
+// Set any table field as a 64bit int, regardless of type what it is.
+inline bool SetAnyFieldI(Table *table, const reflection::Field &field,
+ int64_t val) {
+ auto field_ptr = table->GetAddressOf(field.offset());
if (!field_ptr) return val == GetFieldDefaultI<int64_t>(field);
- SetAnyValueI(field.type()->base_type(), field_ptr, val);
- return true;
-}
-
-// Set any table field as a double, regardless of what type it is.
-inline bool SetAnyFieldF(Table *table, const reflection::Field &field,
- double val) {
- auto field_ptr = table->GetAddressOf(field.offset());
+ SetAnyValueI(field.type()->base_type(), field_ptr, val);
+ return true;
+}
+
+// Set any table field as a double, regardless of what type it is.
+inline bool SetAnyFieldF(Table *table, const reflection::Field &field,
+ double val) {
+ auto field_ptr = table->GetAddressOf(field.offset());
if (!field_ptr) return val == GetFieldDefaultF<double>(field);
- SetAnyValueF(field.type()->base_type(), field_ptr, val);
- return true;
-}
-
-// Set any table field as a string, regardless of what type it is.
-inline bool SetAnyFieldS(Table *table, const reflection::Field &field,
+ SetAnyValueF(field.type()->base_type(), field_ptr, val);
+ return true;
+}
+
+// Set any table field as a string, regardless of what type it is.
+inline bool SetAnyFieldS(Table *table, const reflection::Field &field,
+ const char *val) {
+ auto field_ptr = table->GetAddressOf(field.offset());
+ if (!field_ptr) return false;
+ SetAnyValueS(field.type()->base_type(), field_ptr, val);
+ return true;
+}
+
+// Set any struct field as a 64bit int, regardless of type what it is.
+inline void SetAnyFieldI(Struct *st, const reflection::Field &field,
+ int64_t val) {
+ SetAnyValueI(field.type()->base_type(), st->GetAddressOf(field.offset()),
+ val);
+}
+
+// Set any struct field as a double, regardless of type what it is.
+inline void SetAnyFieldF(Struct *st, const reflection::Field &field,
+ double val) {
+ SetAnyValueF(field.type()->base_type(), st->GetAddressOf(field.offset()),
+ val);
+}
+
+// Set any struct field as a string, regardless of type what it is.
+inline void SetAnyFieldS(Struct *st, const reflection::Field &field,
const char *val) {
- auto field_ptr = table->GetAddressOf(field.offset());
- if (!field_ptr) return false;
- SetAnyValueS(field.type()->base_type(), field_ptr, val);
- return true;
-}
-
-// Set any struct field as a 64bit int, regardless of type what it is.
-inline void SetAnyFieldI(Struct *st, const reflection::Field &field,
- int64_t val) {
- SetAnyValueI(field.type()->base_type(), st->GetAddressOf(field.offset()),
- val);
-}
-
-// Set any struct field as a double, regardless of type what it is.
-inline void SetAnyFieldF(Struct *st, const reflection::Field &field,
- double val) {
- SetAnyValueF(field.type()->base_type(), st->GetAddressOf(field.offset()),
- val);
-}
-
-// Set any struct field as a string, regardless of type what it is.
-inline void SetAnyFieldS(Struct *st, const reflection::Field &field,
- const char *val) {
- SetAnyValueS(field.type()->base_type(), st->GetAddressOf(field.offset()),
- val);
-}
-
-// Set any vector element as a 64bit int, regardless of type what it is.
-inline void SetAnyVectorElemI(VectorOfAny *vec, reflection::BaseType elem_type,
- size_t i, int64_t val) {
- SetAnyValueI(elem_type, vec->Data() + GetTypeSize(elem_type) * i, val);
-}
-
-// Set any vector element as a double, regardless of type what it is.
-inline void SetAnyVectorElemF(VectorOfAny *vec, reflection::BaseType elem_type,
- size_t i, double val) {
- SetAnyValueF(elem_type, vec->Data() + GetTypeSize(elem_type) * i, val);
-}
-
-// Set any vector element as a string, regardless of type what it is.
-inline void SetAnyVectorElemS(VectorOfAny *vec, reflection::BaseType elem_type,
- size_t i, const char *val) {
- SetAnyValueS(elem_type, vec->Data() + GetTypeSize(elem_type) * i, val);
-}
-
-// ------------------------- RESIZING SETTERS -------------------------
-
-// "smart" pointer for use with resizing vectors: turns a pointer inside
-// a vector into a relative offset, such that it is not affected by resizes.
-template<typename T, typename U> class pointer_inside_vector {
- public:
- pointer_inside_vector(T *ptr, std::vector<U> &vec)
+ SetAnyValueS(field.type()->base_type(), st->GetAddressOf(field.offset()),
+ val);
+}
+
+// Set any vector element as a 64bit int, regardless of type what it is.
+inline void SetAnyVectorElemI(VectorOfAny *vec, reflection::BaseType elem_type,
+ size_t i, int64_t val) {
+ SetAnyValueI(elem_type, vec->Data() + GetTypeSize(elem_type) * i, val);
+}
+
+// Set any vector element as a double, regardless of type what it is.
+inline void SetAnyVectorElemF(VectorOfAny *vec, reflection::BaseType elem_type,
+ size_t i, double val) {
+ SetAnyValueF(elem_type, vec->Data() + GetTypeSize(elem_type) * i, val);
+}
+
+// Set any vector element as a string, regardless of type what it is.
+inline void SetAnyVectorElemS(VectorOfAny *vec, reflection::BaseType elem_type,
+ size_t i, const char *val) {
+ SetAnyValueS(elem_type, vec->Data() + GetTypeSize(elem_type) * i, val);
+}
+
+// ------------------------- RESIZING SETTERS -------------------------
+
+// "smart" pointer for use with resizing vectors: turns a pointer inside
+// a vector into a relative offset, such that it is not affected by resizes.
+template<typename T, typename U> class pointer_inside_vector {
+ public:
+ pointer_inside_vector(T *ptr, std::vector<U> &vec)
: offset_(reinterpret_cast<uint8_t *>(ptr) -
reinterpret_cast<uint8_t *>(flatbuffers::vector_data(vec))),
vec_(vec) {}
-
- T *operator*() const {
- return reinterpret_cast<T *>(
+
+ T *operator*() const {
+ return reinterpret_cast<T *>(
reinterpret_cast<uint8_t *>(flatbuffers::vector_data(vec_)) + offset_);
- }
+ }
T *operator->() const { return operator*(); }
- private:
- size_t offset_;
- std::vector<U> &vec_;
-};
-
-// Helper to create the above easily without specifying template args.
+ private:
+ size_t offset_;
+ std::vector<U> &vec_;
+};
+
+// Helper to create the above easily without specifying template args.
template<typename T, typename U>
pointer_inside_vector<T, U> piv(T *ptr, std::vector<U> &vec) {
- return pointer_inside_vector<T, U>(ptr, vec);
-}
-
+ return pointer_inside_vector<T, U>(ptr, vec);
+}
+
inline const char *UnionTypeFieldSuffix() { return "_type"; }
-// Helper to figure out the actual table type a union refers to.
-inline const reflection::Object &GetUnionType(
- const reflection::Schema &schema, const reflection::Object &parent,
- const reflection::Field &unionfield, const Table &table) {
- auto enumdef = schema.enums()->Get(unionfield.type()->index());
- // TODO: this is clumsy and slow, but no other way to find it?
- auto type_field = parent.fields()->LookupByKey(
+// Helper to figure out the actual table type a union refers to.
+inline const reflection::Object &GetUnionType(
+ const reflection::Schema &schema, const reflection::Object &parent,
+ const reflection::Field &unionfield, const Table &table) {
+ auto enumdef = schema.enums()->Get(unionfield.type()->index());
+ // TODO: this is clumsy and slow, but no other way to find it?
+ auto type_field = parent.fields()->LookupByKey(
(unionfield.name()->str() + UnionTypeFieldSuffix()).c_str());
FLATBUFFERS_ASSERT(type_field);
- auto union_type = GetFieldI<uint8_t>(table, *type_field);
- auto enumval = enumdef->values()->LookupByKey(union_type);
- return *enumval->object();
-}
-
-// Changes the contents of a string inside a FlatBuffer. FlatBuffer must
-// live inside a std::vector so we can resize the buffer if needed.
-// "str" must live inside "flatbuf" and may be invalidated after this call.
-// If your FlatBuffer's root table is not the schema's root table, you should
-// pass in your root_table type as well.
-void SetString(const reflection::Schema &schema, const std::string &val,
- const String *str, std::vector<uint8_t> *flatbuf,
- const reflection::Object *root_table = nullptr);
-
-// Resizes a flatbuffers::Vector inside a FlatBuffer. FlatBuffer must
-// live inside a std::vector so we can resize the buffer if needed.
-// "vec" must live inside "flatbuf" and may be invalidated after this call.
-// If your FlatBuffer's root table is not the schema's root table, you should
-// pass in your root_table type as well.
-uint8_t *ResizeAnyVector(const reflection::Schema &schema, uoffset_t newsize,
- const VectorOfAny *vec, uoffset_t num_elems,
- uoffset_t elem_size, std::vector<uint8_t> *flatbuf,
- const reflection::Object *root_table = nullptr);
-
+ auto union_type = GetFieldI<uint8_t>(table, *type_field);
+ auto enumval = enumdef->values()->LookupByKey(union_type);
+ return *enumval->object();
+}
+
+// Changes the contents of a string inside a FlatBuffer. FlatBuffer must
+// live inside a std::vector so we can resize the buffer if needed.
+// "str" must live inside "flatbuf" and may be invalidated after this call.
+// If your FlatBuffer's root table is not the schema's root table, you should
+// pass in your root_table type as well.
+void SetString(const reflection::Schema &schema, const std::string &val,
+ const String *str, std::vector<uint8_t> *flatbuf,
+ const reflection::Object *root_table = nullptr);
+
+// Resizes a flatbuffers::Vector inside a FlatBuffer. FlatBuffer must
+// live inside a std::vector so we can resize the buffer if needed.
+// "vec" must live inside "flatbuf" and may be invalidated after this call.
+// If your FlatBuffer's root table is not the schema's root table, you should
+// pass in your root_table type as well.
+uint8_t *ResizeAnyVector(const reflection::Schema &schema, uoffset_t newsize,
+ const VectorOfAny *vec, uoffset_t num_elems,
+ uoffset_t elem_size, std::vector<uint8_t> *flatbuf,
+ const reflection::Object *root_table = nullptr);
+
template<typename T>
-void ResizeVector(const reflection::Schema &schema, uoffset_t newsize, T val,
- const Vector<T> *vec, std::vector<uint8_t> *flatbuf,
- const reflection::Object *root_table = nullptr) {
- auto delta_elem = static_cast<int>(newsize) - static_cast<int>(vec->size());
+void ResizeVector(const reflection::Schema &schema, uoffset_t newsize, T val,
+ const Vector<T> *vec, std::vector<uint8_t> *flatbuf,
+ const reflection::Object *root_table = nullptr) {
+ auto delta_elem = static_cast<int>(newsize) - static_cast<int>(vec->size());
auto newelems = ResizeAnyVector(
schema, newsize, reinterpret_cast<const VectorOfAny *>(vec), vec->size(),
static_cast<uoffset_t>(sizeof(T)), flatbuf, root_table);
- // Set new elements to "val".
- for (int i = 0; i < delta_elem; i++) {
- auto loc = newelems + i * sizeof(T);
+ // Set new elements to "val".
+ for (int i = 0; i < delta_elem; i++) {
+ auto loc = newelems + i * sizeof(T);
auto is_scalar = flatbuffers::is_scalar<T>::value;
- if (is_scalar) {
- WriteScalar(loc, val);
- } else { // struct
- *reinterpret_cast<T *>(loc) = val;
- }
- }
-}
-
-// Adds any new data (in the form of a new FlatBuffer) to an existing
-// FlatBuffer. This can be used when any of the above methods are not
-// sufficient, in particular for adding new tables and new fields.
-// This is potentially slightly less efficient than a FlatBuffer constructed
-// in one piece, since the new FlatBuffer doesn't share any vtables with the
-// existing one.
-// The return value can now be set using Vector::MutateOffset or SetFieldT
-// below.
-const uint8_t *AddFlatBuffer(std::vector<uint8_t> &flatbuf,
- const uint8_t *newbuf, size_t newlen);
-
-inline bool SetFieldT(Table *table, const reflection::Field &field,
- const uint8_t *val) {
+ if (is_scalar) {
+ WriteScalar(loc, val);
+ } else { // struct
+ *reinterpret_cast<T *>(loc) = val;
+ }
+ }
+}
+
+// Adds any new data (in the form of a new FlatBuffer) to an existing
+// FlatBuffer. This can be used when any of the above methods are not
+// sufficient, in particular for adding new tables and new fields.
+// This is potentially slightly less efficient than a FlatBuffer constructed
+// in one piece, since the new FlatBuffer doesn't share any vtables with the
+// existing one.
+// The return value can now be set using Vector::MutateOffset or SetFieldT
+// below.
+const uint8_t *AddFlatBuffer(std::vector<uint8_t> &flatbuf,
+ const uint8_t *newbuf, size_t newlen);
+
+inline bool SetFieldT(Table *table, const reflection::Field &field,
+ const uint8_t *val) {
FLATBUFFERS_ASSERT(sizeof(uoffset_t) ==
GetTypeSize(field.type()->base_type()));
- return table->SetPointer(field.offset(), val);
-}
-
-// ------------------------- COPYING -------------------------
-
-// Generic copying of tables from a FlatBuffer into a FlatBuffer builder.
-// Can be used to do any kind of merging/selecting you may want to do out
-// of existing buffers. Also useful to reconstruct a whole buffer if the
-// above resizing functionality has introduced garbage in a buffer you want
-// to remove.
-// Note: this does not deal with DAGs correctly. If the table passed forms a
+ return table->SetPointer(field.offset(), val);
+}
+
+// ------------------------- COPYING -------------------------
+
+// Generic copying of tables from a FlatBuffer into a FlatBuffer builder.
+// Can be used to do any kind of merging/selecting you may want to do out
+// of existing buffers. Also useful to reconstruct a whole buffer if the
+// above resizing functionality has introduced garbage in a buffer you want
+// to remove.
+// Note: this does not deal with DAGs correctly. If the table passed forms a
// DAG, the copy will be a tree instead (with duplicates). Strings can be
// shared however, by passing true for use_string_pooling.
-
-Offset<const Table *> CopyTable(FlatBufferBuilder &fbb,
- const reflection::Schema &schema,
- const reflection::Object &objectdef,
+
+Offset<const Table *> CopyTable(FlatBufferBuilder &fbb,
+ const reflection::Schema &schema,
+ const reflection::Object &objectdef,
const Table &table,
bool use_string_pooling = false);
-
+
// Verifies the provided flatbuffer using reflection.
// root should point to the root type for this flatbuffer.
// buf should point to the start of flatbuffer data.
@@ -497,6 +497,6 @@ bool Verify(const reflection::Schema &schema, const reflection::Object &root,
const uint8_t *buf, size_t length, uoffset_t max_depth = 64,
uoffset_t max_tables = 1000000);
-} // namespace flatbuffers
-
-#endif // FLATBUFFERS_REFLECTION_H_
+} // namespace flatbuffers
+
+#endif // FLATBUFFERS_REFLECTION_H_
diff --git a/contrib/libs/flatbuffers/include/flatbuffers/reflection_generated.h b/contrib/libs/flatbuffers/include/flatbuffers/reflection_generated.h
index 26eb8cea05..93dc4b88b7 100644
--- a/contrib/libs/flatbuffers/include/flatbuffers/reflection_generated.h
+++ b/contrib/libs/flatbuffers/include/flatbuffers/reflection_generated.h
@@ -1,29 +1,29 @@
-// automatically generated by the FlatBuffers compiler, do not modify
-
+// automatically generated by the FlatBuffers compiler, do not modify
+
+
+#ifndef FLATBUFFERS_GENERATED_REFLECTION_REFLECTION_H_
+#define FLATBUFFERS_GENERATED_REFLECTION_REFLECTION_H_
-#ifndef FLATBUFFERS_GENERATED_REFLECTION_REFLECTION_H_
-#define FLATBUFFERS_GENERATED_REFLECTION_REFLECTION_H_
-
#include "flatbuffers.h"
-
-namespace reflection {
-
-struct Type;
+
+namespace reflection {
+
+struct Type;
struct TypeBuilder;
struct KeyValue;
struct KeyValueBuilder;
-struct EnumVal;
+struct EnumVal;
struct EnumValBuilder;
-struct Enum;
+struct Enum;
struct EnumBuilder;
-struct Field;
+struct Field;
struct FieldBuilder;
-struct Object;
+struct Object;
struct ObjectBuilder;
struct RPCCall;
@@ -32,31 +32,31 @@ struct RPCCallBuilder;
struct Service;
struct ServiceBuilder;
-struct Schema;
+struct Schema;
struct SchemaBuilder;
-
-enum BaseType {
- None = 0,
- UType = 1,
- Bool = 2,
- Byte = 3,
- UByte = 4,
- Short = 5,
- UShort = 6,
- Int = 7,
- UInt = 8,
- Long = 9,
- ULong = 10,
- Float = 11,
- Double = 12,
- String = 13,
- Vector = 14,
- Obj = 15,
+
+enum BaseType {
+ None = 0,
+ UType = 1,
+ Bool = 2,
+ Byte = 3,
+ UByte = 4,
+ Short = 5,
+ UShort = 6,
+ Int = 7,
+ UInt = 8,
+ Long = 9,
+ ULong = 10,
+ Float = 11,
+ Double = 12,
+ String = 13,
+ Vector = 14,
+ Obj = 15,
Union = 16,
Array = 17,
MaxBaseType = 18
-};
-
+};
+
inline const BaseType (&EnumValuesBaseType())[19] {
static const BaseType values[] = {
None,
@@ -105,15 +105,15 @@ inline const char * const *EnumNamesBaseType() {
"MaxBaseType",
nullptr
};
- return names;
-}
-
+ return names;
+}
+
inline const char *EnumNameBaseType(BaseType e) {
if (flatbuffers::IsOutRange(e, None, MaxBaseType)) return "";
const size_t index = static_cast<size_t>(e);
return EnumNamesBaseType()[index];
}
-
+
enum AdvancedFeatures {
AdvancedArrayFeatures = 1ULL,
AdvancedUnionFeatures = 2ULL,
@@ -152,7 +152,7 @@ inline const char *EnumNameAdvancedFeatures(AdvancedFeatures e) {
return EnumNamesAdvancedFeatures()[index];
}
-struct Type FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
+struct Type FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef TypeBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_BASE_TYPE = 4,
@@ -172,20 +172,20 @@ struct Type FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
uint16_t fixed_length() const {
return GetField<uint16_t>(VT_FIXED_LENGTH, 0);
}
- bool Verify(flatbuffers::Verifier &verifier) const {
- return VerifyTableStart(verifier) &&
+ bool Verify(flatbuffers::Verifier &verifier) const {
+ return VerifyTableStart(verifier) &&
VerifyField<int8_t>(verifier, VT_BASE_TYPE) &&
VerifyField<int8_t>(verifier, VT_ELEMENT) &&
VerifyField<int32_t>(verifier, VT_INDEX) &&
VerifyField<uint16_t>(verifier, VT_FIXED_LENGTH) &&
- verifier.EndTable();
- }
-};
-
-struct TypeBuilder {
+ verifier.EndTable();
+ }
+};
+
+struct TypeBuilder {
typedef Type Table;
- flatbuffers::FlatBufferBuilder &fbb_;
- flatbuffers::uoffset_t start_;
+ flatbuffers::FlatBufferBuilder &fbb_;
+ flatbuffers::uoffset_t start_;
void add_base_type(reflection::BaseType base_type) {
fbb_.AddElement<int8_t>(Type::VT_BASE_TYPE, static_cast<int8_t>(base_type), 0);
}
@@ -202,27 +202,27 @@ struct TypeBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
- flatbuffers::Offset<Type> Finish() {
+ flatbuffers::Offset<Type> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Type>(end);
- return o;
- }
-};
-
+ return o;
+ }
+};
+
inline flatbuffers::Offset<Type> CreateType(
flatbuffers::FlatBufferBuilder &_fbb,
reflection::BaseType base_type = reflection::None,
reflection::BaseType element = reflection::None,
int32_t index = -1,
uint16_t fixed_length = 0) {
- TypeBuilder builder_(_fbb);
- builder_.add_index(index);
+ TypeBuilder builder_(_fbb);
+ builder_.add_index(index);
builder_.add_fixed_length(fixed_length);
- builder_.add_element(element);
- builder_.add_base_type(base_type);
- return builder_.Finish();
-}
-
+ builder_.add_element(element);
+ builder_.add_base_type(base_type);
+ return builder_.Finish();
+}
+
struct KeyValue FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef KeyValueBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
@@ -295,7 +295,7 @@ inline flatbuffers::Offset<KeyValue> CreateKeyValueDirect(
value__);
}
-struct EnumVal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
+struct EnumVal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef EnumValBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_NAME = 4,
@@ -325,26 +325,26 @@ struct EnumVal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *documentation() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *>(VT_DOCUMENTATION);
}
- bool Verify(flatbuffers::Verifier &verifier) const {
- return VerifyTableStart(verifier) &&
+ bool Verify(flatbuffers::Verifier &verifier) const {
+ return VerifyTableStart(verifier) &&
VerifyOffsetRequired(verifier, VT_NAME) &&
verifier.VerifyString(name()) &&
VerifyField<int64_t>(verifier, VT_VALUE) &&
VerifyOffset(verifier, VT_OBJECT) &&
- verifier.VerifyTable(object()) &&
+ verifier.VerifyTable(object()) &&
VerifyOffset(verifier, VT_UNION_TYPE) &&
verifier.VerifyTable(union_type()) &&
VerifyOffset(verifier, VT_DOCUMENTATION) &&
verifier.VerifyVector(documentation()) &&
verifier.VerifyVectorOfStrings(documentation()) &&
- verifier.EndTable();
- }
-};
-
-struct EnumValBuilder {
+ verifier.EndTable();
+ }
+};
+
+struct EnumValBuilder {
typedef EnumVal Table;
- flatbuffers::FlatBufferBuilder &fbb_;
- flatbuffers::uoffset_t start_;
+ flatbuffers::FlatBufferBuilder &fbb_;
+ flatbuffers::uoffset_t start_;
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
fbb_.AddOffset(EnumVal::VT_NAME, name);
}
@@ -364,14 +364,14 @@ struct EnumValBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
- flatbuffers::Offset<EnumVal> Finish() {
+ flatbuffers::Offset<EnumVal> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<EnumVal>(end);
fbb_.Required(o, EnumVal::VT_NAME);
- return o;
- }
-};
-
+ return o;
+ }
+};
+
inline flatbuffers::Offset<EnumVal> CreateEnumVal(
flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::String> name = 0,
@@ -379,15 +379,15 @@ inline flatbuffers::Offset<EnumVal> CreateEnumVal(
flatbuffers::Offset<reflection::Object> object = 0,
flatbuffers::Offset<reflection::Type> union_type = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation = 0) {
- EnumValBuilder builder_(_fbb);
- builder_.add_value(value);
+ EnumValBuilder builder_(_fbb);
+ builder_.add_value(value);
builder_.add_documentation(documentation);
builder_.add_union_type(union_type);
- builder_.add_object(object);
- builder_.add_name(name);
- return builder_.Finish();
-}
-
+ builder_.add_object(object);
+ builder_.add_name(name);
+ return builder_.Finish();
+}
+
inline flatbuffers::Offset<EnumVal> CreateEnumValDirect(
flatbuffers::FlatBufferBuilder &_fbb,
const char *name = nullptr,
@@ -406,7 +406,7 @@ inline flatbuffers::Offset<EnumVal> CreateEnumValDirect(
documentation__);
}
-struct Enum FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
+struct Enum FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef EnumBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_NAME = 4,
@@ -440,30 +440,30 @@ struct Enum FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *documentation() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *>(VT_DOCUMENTATION);
}
- bool Verify(flatbuffers::Verifier &verifier) const {
- return VerifyTableStart(verifier) &&
+ bool Verify(flatbuffers::Verifier &verifier) const {
+ return VerifyTableStart(verifier) &&
VerifyOffsetRequired(verifier, VT_NAME) &&
verifier.VerifyString(name()) &&
VerifyOffsetRequired(verifier, VT_VALUES) &&
verifier.VerifyVector(values()) &&
- verifier.VerifyVectorOfTables(values()) &&
+ verifier.VerifyVectorOfTables(values()) &&
VerifyField<uint8_t>(verifier, VT_IS_UNION) &&
VerifyOffsetRequired(verifier, VT_UNDERLYING_TYPE) &&
- verifier.VerifyTable(underlying_type()) &&
+ verifier.VerifyTable(underlying_type()) &&
VerifyOffset(verifier, VT_ATTRIBUTES) &&
verifier.VerifyVector(attributes()) &&
verifier.VerifyVectorOfTables(attributes()) &&
VerifyOffset(verifier, VT_DOCUMENTATION) &&
verifier.VerifyVector(documentation()) &&
verifier.VerifyVectorOfStrings(documentation()) &&
- verifier.EndTable();
- }
-};
-
-struct EnumBuilder {
+ verifier.EndTable();
+ }
+};
+
+struct EnumBuilder {
typedef Enum Table;
- flatbuffers::FlatBufferBuilder &fbb_;
- flatbuffers::uoffset_t start_;
+ flatbuffers::FlatBufferBuilder &fbb_;
+ flatbuffers::uoffset_t start_;
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
fbb_.AddOffset(Enum::VT_NAME, name);
}
@@ -486,16 +486,16 @@ struct EnumBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
- flatbuffers::Offset<Enum> Finish() {
+ flatbuffers::Offset<Enum> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Enum>(end);
fbb_.Required(o, Enum::VT_NAME);
fbb_.Required(o, Enum::VT_VALUES);
fbb_.Required(o, Enum::VT_UNDERLYING_TYPE);
- return o;
- }
-};
-
+ return o;
+ }
+};
+
inline flatbuffers::Offset<Enum> CreateEnum(
flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::String> name = 0,
@@ -504,16 +504,16 @@ inline flatbuffers::Offset<Enum> CreateEnum(
flatbuffers::Offset<reflection::Type> underlying_type = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>> attributes = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation = 0) {
- EnumBuilder builder_(_fbb);
+ EnumBuilder builder_(_fbb);
builder_.add_documentation(documentation);
builder_.add_attributes(attributes);
- builder_.add_underlying_type(underlying_type);
- builder_.add_values(values);
- builder_.add_name(name);
- builder_.add_is_union(is_union);
- return builder_.Finish();
-}
-
+ builder_.add_underlying_type(underlying_type);
+ builder_.add_values(values);
+ builder_.add_name(name);
+ builder_.add_is_union(is_union);
+ return builder_.Finish();
+}
+
inline flatbuffers::Offset<Enum> CreateEnumDirect(
flatbuffers::FlatBufferBuilder &_fbb,
const char *name = nullptr,
@@ -536,7 +536,7 @@ inline flatbuffers::Offset<Enum> CreateEnumDirect(
documentation__);
}
-struct Field FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
+struct Field FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef FieldBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_NAME = 4,
@@ -594,12 +594,12 @@ struct Field FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
bool optional() const {
return GetField<uint8_t>(VT_OPTIONAL, 0) != 0;
}
- bool Verify(flatbuffers::Verifier &verifier) const {
- return VerifyTableStart(verifier) &&
+ bool Verify(flatbuffers::Verifier &verifier) const {
+ return VerifyTableStart(verifier) &&
VerifyOffsetRequired(verifier, VT_NAME) &&
verifier.VerifyString(name()) &&
VerifyOffsetRequired(verifier, VT_TYPE) &&
- verifier.VerifyTable(type()) &&
+ verifier.VerifyTable(type()) &&
VerifyField<uint16_t>(verifier, VT_ID) &&
VerifyField<uint16_t>(verifier, VT_OFFSET) &&
VerifyField<int64_t>(verifier, VT_DEFAULT_INTEGER) &&
@@ -614,14 +614,14 @@ struct Field FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
verifier.VerifyVector(documentation()) &&
verifier.VerifyVectorOfStrings(documentation()) &&
VerifyField<uint8_t>(verifier, VT_OPTIONAL) &&
- verifier.EndTable();
- }
-};
-
-struct FieldBuilder {
+ verifier.EndTable();
+ }
+};
+
+struct FieldBuilder {
typedef Field Table;
- flatbuffers::FlatBufferBuilder &fbb_;
- flatbuffers::uoffset_t start_;
+ flatbuffers::FlatBufferBuilder &fbb_;
+ flatbuffers::uoffset_t start_;
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
fbb_.AddOffset(Field::VT_NAME, name);
}
@@ -662,15 +662,15 @@ struct FieldBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
- flatbuffers::Offset<Field> Finish() {
+ flatbuffers::Offset<Field> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Field>(end);
fbb_.Required(o, Field::VT_NAME);
fbb_.Required(o, Field::VT_TYPE);
- return o;
- }
-};
-
+ return o;
+ }
+};
+
inline flatbuffers::Offset<Field> CreateField(
flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::String> name = 0,
@@ -685,22 +685,22 @@ inline flatbuffers::Offset<Field> CreateField(
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>> attributes = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation = 0,
bool optional = false) {
- FieldBuilder builder_(_fbb);
- builder_.add_default_real(default_real);
- builder_.add_default_integer(default_integer);
+ FieldBuilder builder_(_fbb);
+ builder_.add_default_real(default_real);
+ builder_.add_default_integer(default_integer);
builder_.add_documentation(documentation);
builder_.add_attributes(attributes);
- builder_.add_type(type);
- builder_.add_name(name);
- builder_.add_offset(offset);
- builder_.add_id(id);
+ builder_.add_type(type);
+ builder_.add_name(name);
+ builder_.add_offset(offset);
+ builder_.add_id(id);
builder_.add_optional(optional);
- builder_.add_key(key);
- builder_.add_required(required);
- builder_.add_deprecated(deprecated);
- return builder_.Finish();
-}
-
+ builder_.add_key(key);
+ builder_.add_required(required);
+ builder_.add_deprecated(deprecated);
+ return builder_.Finish();
+}
+
inline flatbuffers::Offset<Field> CreateFieldDirect(
flatbuffers::FlatBufferBuilder &_fbb,
const char *name = nullptr,
@@ -734,7 +734,7 @@ inline flatbuffers::Offset<Field> CreateFieldDirect(
optional);
}
-struct Object FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
+struct Object FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef ObjectBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_NAME = 4,
@@ -772,13 +772,13 @@ struct Object FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *documentation() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *>(VT_DOCUMENTATION);
}
- bool Verify(flatbuffers::Verifier &verifier) const {
- return VerifyTableStart(verifier) &&
+ bool Verify(flatbuffers::Verifier &verifier) const {
+ return VerifyTableStart(verifier) &&
VerifyOffsetRequired(verifier, VT_NAME) &&
verifier.VerifyString(name()) &&
VerifyOffsetRequired(verifier, VT_FIELDS) &&
verifier.VerifyVector(fields()) &&
- verifier.VerifyVectorOfTables(fields()) &&
+ verifier.VerifyVectorOfTables(fields()) &&
VerifyField<uint8_t>(verifier, VT_IS_STRUCT) &&
VerifyField<int32_t>(verifier, VT_MINALIGN) &&
VerifyField<int32_t>(verifier, VT_BYTESIZE) &&
@@ -788,14 +788,14 @@ struct Object FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
VerifyOffset(verifier, VT_DOCUMENTATION) &&
verifier.VerifyVector(documentation()) &&
verifier.VerifyVectorOfStrings(documentation()) &&
- verifier.EndTable();
- }
-};
-
-struct ObjectBuilder {
+ verifier.EndTable();
+ }
+};
+
+struct ObjectBuilder {
typedef Object Table;
- flatbuffers::FlatBufferBuilder &fbb_;
- flatbuffers::uoffset_t start_;
+ flatbuffers::FlatBufferBuilder &fbb_;
+ flatbuffers::uoffset_t start_;
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
fbb_.AddOffset(Object::VT_NAME, name);
}
@@ -821,15 +821,15 @@ struct ObjectBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
- flatbuffers::Offset<Object> Finish() {
+ flatbuffers::Offset<Object> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Object>(end);
fbb_.Required(o, Object::VT_NAME);
fbb_.Required(o, Object::VT_FIELDS);
- return o;
- }
-};
-
+ return o;
+ }
+};
+
inline flatbuffers::Offset<Object> CreateObject(
flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::String> name = 0,
@@ -839,17 +839,17 @@ inline flatbuffers::Offset<Object> CreateObject(
int32_t bytesize = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>> attributes = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation = 0) {
- ObjectBuilder builder_(_fbb);
+ ObjectBuilder builder_(_fbb);
builder_.add_documentation(documentation);
builder_.add_attributes(attributes);
- builder_.add_bytesize(bytesize);
- builder_.add_minalign(minalign);
- builder_.add_fields(fields);
- builder_.add_name(name);
- builder_.add_is_struct(is_struct);
- return builder_.Finish();
-}
-
+ builder_.add_bytesize(bytesize);
+ builder_.add_minalign(minalign);
+ builder_.add_fields(fields);
+ builder_.add_name(name);
+ builder_.add_is_struct(is_struct);
+ return builder_.Finish();
+}
+
inline flatbuffers::Offset<Object> CreateObjectDirect(
flatbuffers::FlatBufferBuilder &_fbb,
const char *name = nullptr,
@@ -1093,7 +1093,7 @@ inline flatbuffers::Offset<Service> CreateServiceDirect(
documentation__);
}
-struct Schema FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
+struct Schema FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef SchemaBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_OBJECTS = 4,
@@ -1125,32 +1125,32 @@ struct Schema FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
reflection::AdvancedFeatures advanced_features() const {
return static_cast<reflection::AdvancedFeatures>(GetField<uint64_t>(VT_ADVANCED_FEATURES, 0));
}
- bool Verify(flatbuffers::Verifier &verifier) const {
- return VerifyTableStart(verifier) &&
+ bool Verify(flatbuffers::Verifier &verifier) const {
+ return VerifyTableStart(verifier) &&
VerifyOffsetRequired(verifier, VT_OBJECTS) &&
verifier.VerifyVector(objects()) &&
- verifier.VerifyVectorOfTables(objects()) &&
+ verifier.VerifyVectorOfTables(objects()) &&
VerifyOffsetRequired(verifier, VT_ENUMS) &&
verifier.VerifyVector(enums()) &&
- verifier.VerifyVectorOfTables(enums()) &&
+ verifier.VerifyVectorOfTables(enums()) &&
VerifyOffset(verifier, VT_FILE_IDENT) &&
verifier.VerifyString(file_ident()) &&
VerifyOffset(verifier, VT_FILE_EXT) &&
verifier.VerifyString(file_ext()) &&
VerifyOffset(verifier, VT_ROOT_TABLE) &&
- verifier.VerifyTable(root_table()) &&
+ verifier.VerifyTable(root_table()) &&
VerifyOffset(verifier, VT_SERVICES) &&
verifier.VerifyVector(services()) &&
verifier.VerifyVectorOfTables(services()) &&
VerifyField<uint64_t>(verifier, VT_ADVANCED_FEATURES) &&
- verifier.EndTable();
- }
-};
-
-struct SchemaBuilder {
+ verifier.EndTable();
+ }
+};
+
+struct SchemaBuilder {
typedef Schema Table;
- flatbuffers::FlatBufferBuilder &fbb_;
- flatbuffers::uoffset_t start_;
+ flatbuffers::FlatBufferBuilder &fbb_;
+ flatbuffers::uoffset_t start_;
void add_objects(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<reflection::Object>>> objects) {
fbb_.AddOffset(Schema::VT_OBJECTS, objects);
}
@@ -1176,15 +1176,15 @@ struct SchemaBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
- flatbuffers::Offset<Schema> Finish() {
+ flatbuffers::Offset<Schema> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Schema>(end);
fbb_.Required(o, Schema::VT_OBJECTS);
fbb_.Required(o, Schema::VT_ENUMS);
- return o;
- }
-};
-
+ return o;
+ }
+};
+
inline flatbuffers::Offset<Schema> CreateSchema(
flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<reflection::Object>>> objects = 0,
@@ -1194,17 +1194,17 @@ inline flatbuffers::Offset<Schema> CreateSchema(
flatbuffers::Offset<reflection::Object> root_table = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<reflection::Service>>> services = 0,
reflection::AdvancedFeatures advanced_features = static_cast<reflection::AdvancedFeatures>(0)) {
- SchemaBuilder builder_(_fbb);
+ SchemaBuilder builder_(_fbb);
builder_.add_advanced_features(advanced_features);
builder_.add_services(services);
- builder_.add_root_table(root_table);
- builder_.add_file_ext(file_ext);
- builder_.add_file_ident(file_ident);
- builder_.add_enums(enums);
- builder_.add_objects(objects);
- return builder_.Finish();
-}
-
+ builder_.add_root_table(root_table);
+ builder_.add_file_ext(file_ext);
+ builder_.add_file_ident(file_ident);
+ builder_.add_enums(enums);
+ builder_.add_objects(objects);
+ return builder_.Finish();
+}
+
inline flatbuffers::Offset<Schema> CreateSchemaDirect(
flatbuffers::FlatBufferBuilder &_fbb,
std::vector<flatbuffers::Offset<reflection::Object>> *objects = nullptr,
@@ -1229,11 +1229,11 @@ inline flatbuffers::Offset<Schema> CreateSchemaDirect(
services__,
advanced_features);
}
-
+
inline const reflection::Schema *GetSchema(const void *buf) {
return flatbuffers::GetRoot<reflection::Schema>(buf);
}
-
+
inline const reflection::Schema *GetSizePrefixedSchema(const void *buf) {
return flatbuffers::GetSizePrefixedRoot<reflection::Schema>(buf);
}
@@ -1241,17 +1241,17 @@ inline const reflection::Schema *GetSizePrefixedSchema(const void *buf) {
inline const char *SchemaIdentifier() {
return "BFBS";
}
-
+
inline bool SchemaBufferHasIdentifier(const void *buf) {
return flatbuffers::BufferHasIdentifier(
buf, SchemaIdentifier());
}
-
+
inline bool VerifySchemaBuffer(
flatbuffers::Verifier &verifier) {
return verifier.VerifyBuffer<reflection::Schema>(SchemaIdentifier());
}
-
+
inline bool VerifySizePrefixedSchemaBuffer(
flatbuffers::Verifier &verifier) {
return verifier.VerifySizePrefixedBuffer<reflection::Schema>(SchemaIdentifier());
@@ -1260,7 +1260,7 @@ inline bool VerifySizePrefixedSchemaBuffer(
inline const char *SchemaExtension() {
return "bfbs";
}
-
+
inline void FinishSchemaBuffer(
flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<reflection::Schema> root) {
@@ -1273,6 +1273,6 @@ inline void FinishSizePrefixedSchemaBuffer(
fbb.FinishSizePrefixed(root, SchemaIdentifier());
}
-} // namespace reflection
-
-#endif // FLATBUFFERS_GENERATED_REFLECTION_REFLECTION_H_
+} // namespace reflection
+
+#endif // FLATBUFFERS_GENERATED_REFLECTION_REFLECTION_H_
diff --git a/contrib/libs/flatbuffers/include/flatbuffers/util.h b/contrib/libs/flatbuffers/include/flatbuffers/util.h
index b7ef84ff37..4493c561c2 100644
--- a/contrib/libs/flatbuffers/include/flatbuffers/util.h
+++ b/contrib/libs/flatbuffers/include/flatbuffers/util.h
@@ -1,22 +1,22 @@
-/*
- * Copyright 2014 Google Inc. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef FLATBUFFERS_UTIL_H_
-#define FLATBUFFERS_UTIL_H_
-
+/*
+ * Copyright 2014 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FLATBUFFERS_UTIL_H_
+#define FLATBUFFERS_UTIL_H_
+
#include <errno.h>
#include "base.h"
@@ -30,10 +30,10 @@
#endif // FLATBUFFERS_PREFER_PRINTF
#include <iomanip>
-#include <string>
-
-namespace flatbuffers {
-
+#include <string>
+
+namespace flatbuffers {
+
// @locale-independent functions for ASCII characters set.
// Fast checking that character lies in closed range: [a <= x <= b]
@@ -119,10 +119,10 @@ std::string NumToStringImplWrapper(T t, const char *fmt, int precision = 0) {
}
#endif // FLATBUFFERS_PREFER_PRINTF
-// Convert an integer or floating point value to a string.
-// In contrast to std::stringstream, "char" values are
-// converted to a string of digits, and we don't use scientific notation.
-template<typename T> std::string NumToString(T t) {
+// Convert an integer or floating point value to a string.
+// In contrast to std::stringstream, "char" values are
+// converted to a string of digits, and we don't use scientific notation.
+template<typename T> std::string NumToString(T t) {
// clang-format off
#ifndef FLATBUFFERS_PREFER_PRINTF
@@ -134,14 +134,14 @@ template<typename T> std::string NumToString(T t) {
return NumToStringImplWrapper(v, "%.*lld");
#endif // FLATBUFFERS_PREFER_PRINTF
// clang-format on
-}
-// Avoid char types used as character data.
-template<> inline std::string NumToString<signed char>(signed char t) {
- return NumToString(static_cast<int>(t));
-}
-template<> inline std::string NumToString<unsigned char>(unsigned char t) {
- return NumToString(static_cast<int>(t));
-}
+}
+// Avoid char types used as character data.
+template<> inline std::string NumToString<signed char>(signed char t) {
+ return NumToString(static_cast<int>(t));
+}
+template<> inline std::string NumToString<unsigned char>(unsigned char t) {
+ return NumToString(static_cast<int>(t));
+}
template<> inline std::string NumToString<char>(char t) {
return NumToString(static_cast<int>(t));
}
@@ -151,7 +151,7 @@ template<> inline std::string NumToString<long long>(long long t) {
snprintf(buf, sizeof(buf), "%lld", t);
return std::string(buf);
}
-
+
template<>
inline std::string NumToString<unsigned long long>(unsigned long long t) {
char buf[22]; // (log((1 << 63) - 1) / log(10)) + 1
@@ -160,7 +160,7 @@ inline std::string NumToString<unsigned long long>(unsigned long long t) {
}
#endif // defined(FLATBUFFERS_CPP98_STL)
-// Special versions for floats/doubles.
+// Special versions for floats/doubles.
template<typename T> std::string FloatToString(T t, int precision) {
// clang-format off
@@ -179,26 +179,26 @@ template<typename T> std::string FloatToString(T t, int precision) {
auto s = NumToStringImplWrapper(v, "%0.*f", precision);
#endif // FLATBUFFERS_PREFER_PRINTF
// clang-format on
- // Sadly, std::fixed turns "1" into "1.00000", so here we undo that.
- auto p = s.find_last_not_of('0');
- if (p != std::string::npos) {
+ // Sadly, std::fixed turns "1" into "1.00000", so here we undo that.
+ auto p = s.find_last_not_of('0');
+ if (p != std::string::npos) {
// Strip trailing zeroes. If it is a whole number, keep one zero.
s.resize(p + (s[p] == '.' ? 2 : 1));
- }
- return s;
-}
+ }
+ return s;
+}
template<> inline std::string NumToString<double>(double t) {
return FloatToString(t, 12);
}
-template<> inline std::string NumToString<float>(float t) {
+template<> inline std::string NumToString<float>(float t) {
return FloatToString(t, 6);
-}
-
-// Convert an integer value to a hexadecimal string.
-// The returned string length is always xdigits long, prefixed by 0 digits.
-// For example, IntToStringHex(0x23, 8) returns the string "00000023".
-inline std::string IntToStringHex(int i, int xdigits) {
+}
+
+// Convert an integer value to a hexadecimal string.
+// The returned string length is always xdigits long, prefixed by 0 digits.
+// For example, IntToStringHex(0x23, 8) returns the string "00000023".
+inline std::string IntToStringHex(int i, int xdigits) {
FLATBUFFERS_ASSERT(i >= 0);
// clang-format off
@@ -211,8 +211,8 @@ inline std::string IntToStringHex(int i, int xdigits) {
return NumToStringImplWrapper(i, "%.*X", xdigits);
#endif // FLATBUFFERS_PREFER_PRINTF
// clang-format on
-}
-
+}
+
// clang-format off
// Use locale independent functions {strtod_l, strtof_l, strtoll_l, strtoull_l}.
#if defined(FLATBUFFERS_LOCALE_INDEPENDENT) && (FLATBUFFERS_LOCALE_INDEPENDENT > 0)
@@ -230,34 +230,34 @@ inline std::string IntToStringHex(int i, int xdigits) {
static locale_type Get() { return instance_.locale_; }
};
- #ifdef _MSC_VER
+ #ifdef _MSC_VER
#define __strtoull_impl(s, pe, b) _strtoui64_l(s, pe, b, ClassicLocale::Get())
#define __strtoll_impl(s, pe, b) _strtoi64_l(s, pe, b, ClassicLocale::Get())
#define __strtod_impl(s, pe) _strtod_l(s, pe, ClassicLocale::Get())
#define __strtof_impl(s, pe) _strtof_l(s, pe, ClassicLocale::Get())
- #else
+ #else
#define __strtoull_impl(s, pe, b) strtoull_l(s, pe, b, ClassicLocale::Get())
#define __strtoll_impl(s, pe, b) strtoll_l(s, pe, b, ClassicLocale::Get())
#define __strtod_impl(s, pe) strtod_l(s, pe, ClassicLocale::Get())
#define __strtof_impl(s, pe) strtof_l(s, pe, ClassicLocale::Get())
- #endif
+ #endif
#else
#define __strtod_impl(s, pe) strtod(s, pe)
#define __strtof_impl(s, pe) static_cast<float>(strtod(s, pe))
- #ifdef _MSC_VER
+ #ifdef _MSC_VER
#define __strtoull_impl(s, pe, b) _strtoui64(s, pe, b)
#define __strtoll_impl(s, pe, b) _strtoi64(s, pe, b)
- #else
+ #else
#define __strtoull_impl(s, pe, b) strtoull(s, pe, b)
#define __strtoll_impl(s, pe, b) strtoll(s, pe, b)
- #endif
+ #endif
#endif
inline void strtoval_impl(int64_t *val, const char *str, char **endptr,
int base) {
*val = __strtoll_impl(str, endptr, base);
-}
-
+}
+
inline void strtoval_impl(uint64_t *val, const char *str, char **endptr,
int base) {
*val = __strtoull_impl(str, endptr, base);
@@ -414,123 +414,123 @@ LoadFileFunction SetLoadFileFunction(LoadFileFunction load_file_function);
FileExistsFunction SetFileExistsFunction(
FileExistsFunction file_exists_function);
-// Check if file "name" exists.
+// Check if file "name" exists.
bool FileExists(const char *name);
-
+
// Check if "name" exists and it is also a directory.
bool DirExists(const char *name);
-// Load file "name" into "buf" returning true if successful
-// false otherwise. If "binary" is false data is read
-// using ifstream's text mode, otherwise data is read with
-// no transcoding.
+// Load file "name" into "buf" returning true if successful
+// false otherwise. If "binary" is false data is read
+// using ifstream's text mode, otherwise data is read with
+// no transcoding.
bool LoadFile(const char *name, bool binary, std::string *buf);
-
-// Save data "buf" of length "len" bytes into a file
-// "name" returning true if successful, false otherwise.
-// If "binary" is false data is written using ifstream's
-// text mode, otherwise data is written with no
-// transcoding.
+
+// Save data "buf" of length "len" bytes into a file
+// "name" returning true if successful, false otherwise.
+// If "binary" is false data is written using ifstream's
+// text mode, otherwise data is written with no
+// transcoding.
bool SaveFile(const char *name, const char *buf, size_t len, bool binary);
-
-// Save data "buf" into file "name" returning true if
-// successful, false otherwise. If "binary" is false
-// data is written using ifstream's text mode, otherwise
-// data is written with no transcoding.
-inline bool SaveFile(const char *name, const std::string &buf, bool binary) {
- return SaveFile(name, buf.c_str(), buf.size(), binary);
-}
-
+
+// Save data "buf" into file "name" returning true if
+// successful, false otherwise. If "binary" is false
+// data is written using ifstream's text mode, otherwise
+// data is written with no transcoding.
+inline bool SaveFile(const char *name, const std::string &buf, bool binary) {
+ return SaveFile(name, buf.c_str(), buf.size(), binary);
+}
+
// Functionality for minimalistic portable path handling.
-
+
// The functions below behave correctly regardless of whether posix ('/') or
// Windows ('/' or '\\') separators are used.
// Any new separators inserted are always posix.
FLATBUFFERS_CONSTEXPR char kPathSeparator = '/';
-// Returns the path with the extension, if any, removed.
+// Returns the path with the extension, if any, removed.
std::string StripExtension(const std::string &filepath);
-
-// Returns the extension, if any.
+
+// Returns the extension, if any.
std::string GetExtension(const std::string &filepath);
-
-// Return the last component of the path, after the last separator.
+
+// Return the last component of the path, after the last separator.
std::string StripPath(const std::string &filepath);
-
-// Strip the last component of the path + separator.
+
+// Strip the last component of the path + separator.
std::string StripFileName(const std::string &filepath);
-
+
// Concatenates a path with a filename, regardless of whether the path
-// ends in a separator or not.
+// ends in a separator or not.
std::string ConCatPathFileName(const std::string &path,
const std::string &filename);
-
+
// Replaces any '\\' separators with '/'
std::string PosixPath(const char *path);
-// This function ensure a directory exists, by recursively
-// creating dirs for any parts of the path that don't exist yet.
+// This function ensure a directory exists, by recursively
+// creating dirs for any parts of the path that don't exist yet.
void EnsureDirExists(const std::string &filepath);
-
-// Obtains the absolute path from any other path.
-// Returns the input path if the absolute path couldn't be resolved.
+
+// Obtains the absolute path from any other path.
+// Returns the input path if the absolute path couldn't be resolved.
std::string AbsolutePath(const std::string &filepath);
-
-// To and from UTF-8 unicode conversion functions
-
-// Convert a unicode code point into a UTF-8 representation by appending it
-// to a string. Returns the number of bytes generated.
-inline int ToUTF8(uint32_t ucc, std::string *out) {
+
+// To and from UTF-8 unicode conversion functions
+
+// Convert a unicode code point into a UTF-8 representation by appending it
+// to a string. Returns the number of bytes generated.
+inline int ToUTF8(uint32_t ucc, std::string *out) {
FLATBUFFERS_ASSERT(!(ucc & 0x80000000)); // Top bit can't be set.
- // 6 possible encodings: http://en.wikipedia.org/wiki/UTF-8
- for (int i = 0; i < 6; i++) {
- // Max bits this encoding can represent.
- uint32_t max_bits = 6 + i * 5 + static_cast<int>(!i);
- if (ucc < (1u << max_bits)) { // does it fit?
- // Remaining bits not encoded in the first byte, store 6 bits each
- uint32_t remain_bits = i * 6;
- // Store first byte:
- (*out) += static_cast<char>((0xFE << (max_bits - remain_bits)) |
+ // 6 possible encodings: http://en.wikipedia.org/wiki/UTF-8
+ for (int i = 0; i < 6; i++) {
+ // Max bits this encoding can represent.
+ uint32_t max_bits = 6 + i * 5 + static_cast<int>(!i);
+ if (ucc < (1u << max_bits)) { // does it fit?
+ // Remaining bits not encoded in the first byte, store 6 bits each
+ uint32_t remain_bits = i * 6;
+ // Store first byte:
+ (*out) += static_cast<char>((0xFE << (max_bits - remain_bits)) |
(ucc >> remain_bits));
- // Store remaining bytes:
- for (int j = i - 1; j >= 0; j--) {
- (*out) += static_cast<char>(((ucc >> (j * 6)) & 0x3F) | 0x80);
- }
- return i + 1; // Return the number of bytes added.
- }
- }
+ // Store remaining bytes:
+ for (int j = i - 1; j >= 0; j--) {
+ (*out) += static_cast<char>(((ucc >> (j * 6)) & 0x3F) | 0x80);
+ }
+ return i + 1; // Return the number of bytes added.
+ }
+ }
FLATBUFFERS_ASSERT(0); // Impossible to arrive here.
- return -1;
-}
-
-// Converts whatever prefix of the incoming string corresponds to a valid
-// UTF-8 sequence into a unicode code. The incoming pointer will have been
-// advanced past all bytes parsed.
-// returns -1 upon corrupt UTF-8 encoding (ignore the incoming pointer in
-// this case).
-inline int FromUTF8(const char **in) {
- int len = 0;
- // Count leading 1 bits.
- for (int mask = 0x80; mask >= 0x04; mask >>= 1) {
- if (**in & mask) {
- len++;
- } else {
- break;
- }
- }
+ return -1;
+}
+
+// Converts whatever prefix of the incoming string corresponds to a valid
+// UTF-8 sequence into a unicode code. The incoming pointer will have been
+// advanced past all bytes parsed.
+// returns -1 upon corrupt UTF-8 encoding (ignore the incoming pointer in
+// this case).
+inline int FromUTF8(const char **in) {
+ int len = 0;
+ // Count leading 1 bits.
+ for (int mask = 0x80; mask >= 0x04; mask >>= 1) {
+ if (**in & mask) {
+ len++;
+ } else {
+ break;
+ }
+ }
if ((static_cast<unsigned char>(**in) << len) & 0x80)
return -1; // Bit after leading 1's must be 0.
- if (!len) return *(*in)++;
+ if (!len) return *(*in)++;
// UTF-8 encoded values with a length are between 2 and 4 bytes.
if (len < 2 || len > 4) { return -1; }
- // Grab initial bits of the code.
- int ucc = *(*in)++ & ((1 << (7 - len)) - 1);
- for (int i = 0; i < len - 1; i++) {
- if ((**in & 0xC0) != 0x80) return -1; // Upper bits must 1 0.
- ucc <<= 6;
- ucc |= *(*in)++ & 0x3F; // Grab 6 more bits of the code.
- }
+ // Grab initial bits of the code.
+ int ucc = *(*in)++ & ((1 << (7 - len)) - 1);
+ for (int i = 0; i < len - 1; i++) {
+ if ((**in & 0xC0) != 0x80) return -1; // Upper bits must 1 0.
+ ucc <<= 6;
+ ucc |= *(*in)++ & 0x3F; // Grab 6 more bits of the code.
+ }
// UTF-8 cannot encode values between 0xD800 and 0xDFFF (reserved for
// UTF-16 surrogate pairs).
if (ucc >= 0xD800 && ucc <= 0xDFFF) { return -1; }
@@ -549,38 +549,38 @@ inline int FromUTF8(const char **in) {
if (ucc < 0x10000 || ucc > 0x10FFFF) { return -1; }
break;
}
- return ucc;
-}
-
+ return ucc;
+}
+
#ifndef FLATBUFFERS_PREFER_PRINTF
-// Wraps a string to a maximum length, inserting new lines where necessary. Any
-// existing whitespace will be collapsed down to a single space. A prefix or
-// suffix can be provided, which will be inserted before or after a wrapped
-// line, respectively.
-inline std::string WordWrap(const std::string in, size_t max_length,
- const std::string wrapped_line_prefix,
- const std::string wrapped_line_suffix) {
- std::istringstream in_stream(in);
- std::string wrapped, line, word;
-
- in_stream >> word;
- line = word;
-
- while (in_stream >> word) {
- if ((line.length() + 1 + word.length() + wrapped_line_suffix.length()) <
- max_length) {
- line += " " + word;
- } else {
- wrapped += line + wrapped_line_suffix + "\n";
- line = wrapped_line_prefix + word;
- }
- }
- wrapped += line;
-
- return wrapped;
-}
+// Wraps a string to a maximum length, inserting new lines where necessary. Any
+// existing whitespace will be collapsed down to a single space. A prefix or
+// suffix can be provided, which will be inserted before or after a wrapped
+// line, respectively.
+inline std::string WordWrap(const std::string in, size_t max_length,
+ const std::string wrapped_line_prefix,
+ const std::string wrapped_line_suffix) {
+ std::istringstream in_stream(in);
+ std::string wrapped, line, word;
+
+ in_stream >> word;
+ line = word;
+
+ while (in_stream >> word) {
+ if ((line.length() + 1 + word.length() + wrapped_line_suffix.length()) <
+ max_length) {
+ line += " " + word;
+ } else {
+ wrapped += line + wrapped_line_suffix + "\n";
+ line = wrapped_line_prefix + word;
+ }
+ }
+ wrapped += line;
+
+ return wrapped;
+}
#endif // !FLATBUFFERS_PREFER_PRINTF
-
+
inline bool EscapeString(const char *s, size_t length, std::string *_text,
bool allow_non_utf8, bool natural_utf8) {
std::string &text = *_text;
@@ -693,6 +693,6 @@ bool ReadEnvironmentVariable(const char *var_name,
// MSVC specific: Send all assert reports to STDOUT to prevent CI hangs.
void SetupDefaultCRTReportMode();
-} // namespace flatbuffers
-
-#endif // FLATBUFFERS_UTIL_H_
+} // namespace flatbuffers
+
+#endif // FLATBUFFERS_UTIL_H_