mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
Add CreateVector overload to accept array like (#7095)
This commit is contained in:
@@ -485,7 +485,7 @@ class FlatBufferBuilder {
|
||||
return CreateString(str.c_str(), str.length());
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
// clang-format off
|
||||
#ifdef FLATBUFFERS_HAS_STRING_VIEW
|
||||
/// @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.
|
||||
@@ -625,7 +625,7 @@ class FlatBufferBuilder {
|
||||
AssertScalarT<T>();
|
||||
StartVector(len, sizeof(T));
|
||||
if (len == 0) { return Offset<Vector<T>>(EndVector(len)); }
|
||||
// clang-format off
|
||||
// clang-format off
|
||||
#if FLATBUFFERS_LITTLEENDIAN
|
||||
PushBytes(reinterpret_cast<const uint8_t *>(v), len * sizeof(T));
|
||||
#else
|
||||
@@ -641,6 +641,17 @@ class FlatBufferBuilder {
|
||||
return Offset<Vector<T>>(EndVector(len));
|
||||
}
|
||||
|
||||
/// @brief Serialize an array like object into a FlatBuffer `vector`.
|
||||
/// @tparam T The data type of the array elements.
|
||||
/// @tparam C The type of the array.
|
||||
/// @param[in] array A reference to an array like object of type `T` 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, class C> Offset<Vector<T>> CreateVector(const C &array) {
|
||||
return CreateVector(array.data(), array.size());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Offset<Vector<Offset<T>>> CreateVector(const Offset<T> *v, size_t len) {
|
||||
StartVector(len, sizeof(Offset<T>));
|
||||
|
||||
Reference in New Issue
Block a user