Skip to content

Commit 676afdc

Browse files
committed
Update FlatBuffers source code to 23.5.9
1 parent 8baabdf commit 676afdc

File tree

13 files changed

+653
-291
lines changed

13 files changed

+653
-291
lines changed

3rdparty/flatbuffers/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Origin: https://github.com/google/flatbuffers/tree/v23.1.21
1+
Origin: https://github.com/google/flatbuffers/tree/v23.5.9

3rdparty/flatbuffers/include/flatbuffers/array.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef FLATBUFFERS_ARRAY_H_
1818
#define FLATBUFFERS_ARRAY_H_
1919

20+
#include <cstdint>
2021
#include <memory>
2122

2223
#include "flatbuffers/base.h"
@@ -37,7 +38,7 @@ template<typename T, uint16_t length> class Array {
3738
public:
3839
typedef uint16_t size_type;
3940
typedef typename IndirectHelper<IndirectHelperType>::return_type return_type;
40-
typedef VectorConstIterator<T, return_type> const_iterator;
41+
typedef VectorConstIterator<T, return_type, uoffset_t> const_iterator;
4142
typedef VectorReverseIterator<const_iterator> const_reverse_iterator;
4243

4344
// If T is a LE-scalar or a struct (!scalar_tag::value).
@@ -158,11 +159,13 @@ template<typename T, uint16_t length> class Array {
158159

159160
// Specialization for Array[struct] with access using Offset<void> pointer.
160161
// This specialization used by idl_gen_text.cpp.
161-
template<typename T, uint16_t length> class Array<Offset<T>, length> {
162+
template<typename T, uint16_t length, template<typename> class OffsetT>
163+
class Array<OffsetT<T>, length> {
162164
static_assert(flatbuffers::is_same<T, void>::value, "unexpected type T");
163165

164166
public:
165167
typedef const void *return_type;
168+
typedef uint16_t size_type;
166169

167170
const uint8_t *Data() const { return data_; }
168171

3rdparty/flatbuffers/include/flatbuffers/base.h

+18-9
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <vector>
4444
#include <set>
4545
#include <algorithm>
46+
#include <limits>
4647
#include <iterator>
4748
#include <memory>
4849

@@ -139,8 +140,8 @@
139140
#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
140141

141142
#define FLATBUFFERS_VERSION_MAJOR 23
142-
#define FLATBUFFERS_VERSION_MINOR 1
143-
#define FLATBUFFERS_VERSION_REVISION 21
143+
#define FLATBUFFERS_VERSION_MINOR 5
144+
#define FLATBUFFERS_VERSION_REVISION 9
144145
#define FLATBUFFERS_STRING_EXPAND(X) #X
145146
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
146147
namespace flatbuffers {
@@ -233,12 +234,17 @@ namespace flatbuffers {
233234
}
234235
#define FLATBUFFERS_HAS_STRING_VIEW 1
235236
// Check for absl::string_view
236-
#elif __has_include("absl/strings/string_view.h")
237-
#include "absl/strings/string_view.h"
238-
namespace flatbuffers {
239-
typedef absl::string_view string_view;
240-
}
241-
#define FLATBUFFERS_HAS_STRING_VIEW 1
237+
#elif __has_include("absl/strings/string_view.h") && \
238+
__has_include("absl/base/config.h") && \
239+
(__cplusplus >= 201411)
240+
#include "absl/base/config.h"
241+
#if !defined(ABSL_USES_STD_STRING_VIEW)
242+
#include "absl/strings/string_view.h"
243+
namespace flatbuffers {
244+
typedef absl::string_view string_view;
245+
}
246+
#define FLATBUFFERS_HAS_STRING_VIEW 1
247+
#endif
242248
#endif
243249
#endif // __has_include
244250
#endif // !FLATBUFFERS_HAS_STRING_VIEW
@@ -318,9 +324,11 @@ namespace flatbuffers {
318324
// Also, using a consistent offset type maintains compatibility of serialized
319325
// offset values between 32bit and 64bit systems.
320326
typedef uint32_t uoffset_t;
327+
typedef uint64_t uoffset64_t;
321328

322329
// Signed offsets for references that can go in both directions.
323330
typedef int32_t soffset_t;
331+
typedef int64_t soffset64_t;
324332

325333
// Offset/index used in v-tables, can be changed to uint8_t in
326334
// format forks to save a bit of space if desired.
@@ -329,7 +337,8 @@ typedef uint16_t voffset_t;
329337
typedef uintmax_t largest_scalar_t;
330338

331339
// In 32bits, this evaluates to 2GB - 1
332-
#define FLATBUFFERS_MAX_BUFFER_SIZE ((1ULL << (sizeof(::flatbuffers::soffset_t) * 8 - 1)) - 1)
340+
#define FLATBUFFERS_MAX_BUFFER_SIZE std::numeric_limits<::flatbuffers::soffset_t>::max()
341+
#define FLATBUFFERS_MAX_64_BUFFER_SIZE std::numeric_limits<::flatbuffers::soffset64_t>::max()
333342

334343
// The minimum size buffer that can be a valid flatbuffer.
335344
// Includes the offset to the root table (uoffset_t), the offset to the vtable

3rdparty/flatbuffers/include/flatbuffers/buffer.h

+69-24
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,33 @@ namespace flatbuffers {
2525

2626
// Wrapper for uoffset_t to allow safe template specialization.
2727
// Value is allowed to be 0 to indicate a null object (see e.g. AddOffset).
28-
template<typename T> struct Offset {
29-
uoffset_t o;
28+
template<typename T = void> struct Offset {
29+
// The type of offset to use.
30+
typedef uoffset_t offset_type;
31+
32+
offset_type o;
3033
Offset() : o(0) {}
31-
Offset(uoffset_t _o) : o(_o) {}
32-
Offset<void> Union() const { return Offset<void>(o); }
34+
Offset(const offset_type _o) : o(_o) {}
35+
Offset<> Union() const { return o; }
36+
bool IsNull() const { return !o; }
37+
};
38+
39+
// Wrapper for uoffset64_t Offsets.
40+
template<typename T = void> struct Offset64 {
41+
// The type of offset to use.
42+
typedef uoffset64_t offset_type;
43+
44+
offset_type o;
45+
Offset64() : o(0) {}
46+
Offset64(const offset_type offset) : o(offset) {}
47+
Offset64<> Union() const { return o; }
3348
bool IsNull() const { return !o; }
3449
};
3550

51+
// Litmus check for ensuring the Offsets are the expected size.
52+
static_assert(sizeof(Offset<>) == 4, "Offset has wrong size");
53+
static_assert(sizeof(Offset64<>) == 8, "Offset64 has wrong size");
54+
3655
inline void EndianCheck() {
3756
int endiantest = 1;
3857
// If this fails, see FLATBUFFERS_LITTLEENDIAN above.
@@ -75,35 +94,59 @@ template<typename T> struct IndirectHelper {
7594
typedef T return_type;
7695
typedef T mutable_return_type;
7796
static const size_t element_stride = sizeof(T);
78-
static return_type Read(const uint8_t *p, uoffset_t i) {
97+
98+
static return_type Read(const uint8_t *p, const size_t i) {
7999
return EndianScalar((reinterpret_cast<const T *>(p))[i]);
80100
}
81-
static return_type Read(uint8_t *p, uoffset_t i) {
82-
return Read(const_cast<const uint8_t *>(p), i);
101+
static mutable_return_type Read(uint8_t *p, const size_t i) {
102+
return reinterpret_cast<mutable_return_type>(
103+
Read(const_cast<const uint8_t *>(p), i));
83104
}
84105
};
85-
template<typename T> struct IndirectHelper<Offset<T>> {
106+
107+
// For vector of Offsets.
108+
template<typename T, template<typename> class OffsetT>
109+
struct IndirectHelper<OffsetT<T>> {
86110
typedef const T *return_type;
87111
typedef T *mutable_return_type;
88-
static const size_t element_stride = sizeof(uoffset_t);
89-
static return_type Read(const uint8_t *p, uoffset_t i) {
90-
p += i * sizeof(uoffset_t);
91-
return reinterpret_cast<return_type>(p + ReadScalar<uoffset_t>(p));
112+
typedef typename OffsetT<T>::offset_type offset_type;
113+
static const offset_type element_stride = sizeof(offset_type);
114+
115+
static return_type Read(const uint8_t *const p, const offset_type i) {
116+
// Offsets are relative to themselves, so first update the pointer to
117+
// point to the offset location.
118+
const uint8_t *const offset_location = p + i * element_stride;
119+
120+
// Then read the scalar value of the offset (which may be 32 or 64-bits) and
121+
// then determine the relative location from the offset location.
122+
return reinterpret_cast<return_type>(
123+
offset_location + ReadScalar<offset_type>(offset_location));
92124
}
93-
static mutable_return_type Read(uint8_t *p, uoffset_t i) {
94-
p += i * sizeof(uoffset_t);
95-
return reinterpret_cast<mutable_return_type>(p + ReadScalar<uoffset_t>(p));
125+
static mutable_return_type Read(uint8_t *const p, const offset_type i) {
126+
// Offsets are relative to themselves, so first update the pointer to
127+
// point to the offset location.
128+
uint8_t *const offset_location = p + i * element_stride;
129+
130+
// Then read the scalar value of the offset (which may be 32 or 64-bits) and
131+
// then determine the relative location from the offset location.
132+
return reinterpret_cast<mutable_return_type>(
133+
offset_location + ReadScalar<offset_type>(offset_location));
96134
}
97135
};
136+
137+
// For vector of structs.
98138
template<typename T> struct IndirectHelper<const T *> {
99139
typedef const T *return_type;
100140
typedef T *mutable_return_type;
101141
static const size_t element_stride = sizeof(T);
102-
static return_type Read(const uint8_t *p, uoffset_t i) {
103-
return reinterpret_cast<return_type>(p + i * sizeof(T));
142+
143+
static return_type Read(const uint8_t *const p, const size_t i) {
144+
// Structs are stored inline, relative to the first struct pointer.
145+
return reinterpret_cast<return_type>(p + i * element_stride);
104146
}
105-
static mutable_return_type Read(uint8_t *p, uoffset_t i) {
106-
return reinterpret_cast<mutable_return_type>(p + i * sizeof(T));
147+
static mutable_return_type Read(uint8_t *const p, const size_t i) {
148+
// Structs are stored inline, relative to the first struct pointer.
149+
return reinterpret_cast<mutable_return_type>(p + i * element_stride);
107150
}
108151
};
109152

@@ -130,23 +173,25 @@ inline bool BufferHasIdentifier(const void *buf, const char *identifier,
130173
/// @cond FLATBUFFERS_INTERNAL
131174
// Helpers to get a typed pointer to the root object contained in the buffer.
132175
template<typename T> T *GetMutableRoot(void *buf) {
176+
if (!buf) return nullptr;
133177
EndianCheck();
134178
return reinterpret_cast<T *>(
135179
reinterpret_cast<uint8_t *>(buf) +
136180
EndianScalar(*reinterpret_cast<uoffset_t *>(buf)));
137181
}
138182

139-
template<typename T> T *GetMutableSizePrefixedRoot(void *buf) {
140-
return GetMutableRoot<T>(reinterpret_cast<uint8_t *>(buf) +
141-
sizeof(uoffset_t));
183+
template<typename T, typename SizeT = uoffset_t>
184+
T *GetMutableSizePrefixedRoot(void *buf) {
185+
return GetMutableRoot<T>(reinterpret_cast<uint8_t *>(buf) + sizeof(SizeT));
142186
}
143187

144188
template<typename T> const T *GetRoot(const void *buf) {
145189
return GetMutableRoot<T>(const_cast<void *>(buf));
146190
}
147191

148-
template<typename T> const T *GetSizePrefixedRoot(const void *buf) {
149-
return GetRoot<T>(reinterpret_cast<const uint8_t *>(buf) + sizeof(uoffset_t));
192+
template<typename T, typename SizeT = uoffset_t>
193+
const T *GetSizePrefixedRoot(const void *buf) {
194+
return GetRoot<T>(reinterpret_cast<const uint8_t *>(buf) + sizeof(SizeT));
150195
}
151196

152197
} // namespace flatbuffers

0 commit comments

Comments
 (0)