mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-07 13:53:38 +00:00
Added optional object based API for C++.
Change-Id: If927f3ea3fb3723088fa287f24bdd1ad43c8d1d1 Tested: on Linux.
This commit is contained in:
@@ -984,6 +984,17 @@ FLATBUFFERS_FINAL_CLASS
|
||||
return CreateVector(v.data(), 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
|
||||
Offset<Vector<uint8_t>> CreateVector(const std::vector<bool> &v) {
|
||||
StartVector(v.size(), sizeof(uint8_t));
|
||||
for (auto i = v.size(); i > 0; ) {
|
||||
PushElement(static_cast<uint8_t>(v[--i]));
|
||||
}
|
||||
return Offset<Vector<uint8_t>>(EndVector(v.size()));
|
||||
}
|
||||
|
||||
/// @brief Serialize values returned by a function into a FlatBuffer `vector`.
|
||||
/// This is a convenience function that takes care of iteration for you.
|
||||
/// @tparam T The data type of the `std::vector` elements.
|
||||
@@ -1523,6 +1534,12 @@ class Table {
|
||||
uint8_t data_[1];
|
||||
};
|
||||
|
||||
// Base class for native objects (FlatBuffer data de-serialized into native
|
||||
// C++ data structures).
|
||||
// Contains no functionality, purely documentative.
|
||||
struct NativeTable {
|
||||
};
|
||||
|
||||
// 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,
|
||||
|
||||
@@ -338,7 +338,8 @@ struct IDLOptions {
|
||||
bool skip_unexpected_fields_in_json;
|
||||
bool generate_name_strings;
|
||||
bool escape_proto_identifiers;
|
||||
|
||||
bool generate_object_based_api;
|
||||
|
||||
// Possible options for the more general generator below.
|
||||
enum Language { kJava, kCSharp, kGo, kMAX };
|
||||
|
||||
@@ -358,6 +359,7 @@ struct IDLOptions {
|
||||
skip_unexpected_fields_in_json(false),
|
||||
generate_name_strings(false),
|
||||
escape_proto_identifiers(false),
|
||||
generate_object_based_api(false),
|
||||
lang(IDLOptions::kJava) {}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user