mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-08 06:05:17 +00:00
Fixed vectors of enums in object API serialized incorrectly.
And also added tests for them. Change-Id: I91af1904105435601287291412e82d5066f476a5 Tested: on Linux.
This commit is contained in:
@@ -1731,6 +1731,19 @@ class FlatBufferBuilder {
|
||||
reinterpret_cast<uint8_t **>(buf));
|
||||
}
|
||||
|
||||
|
||||
// @brief Create a vector of scalar type T given as input a vector of scalar
|
||||
// type U, useful with e.g. pre "enum class" enums, or any existing scalar
|
||||
// data of the wrong type.
|
||||
template<typename T, typename U>
|
||||
Offset<Vector<T>> CreateVectorScalarCast(const U *v, size_t len) {
|
||||
AssertScalarT<T>();
|
||||
AssertScalarT<U>();
|
||||
StartVector(len, sizeof(T));
|
||||
for (auto i = len; i > 0;) { PushElement(static_cast<T>(v[--i])); }
|
||||
return Offset<Vector<T>>(EndVector(len));
|
||||
}
|
||||
|
||||
/// @brief Write a struct by itself, typically to be part of a union.
|
||||
template<typename T> Offset<const T *> CreateStruct(const T &structobj) {
|
||||
NotNested();
|
||||
|
||||
Reference in New Issue
Block a user