mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-20 08:05:06 +00:00
Made user-defined attributes available in the reflection data.
Tested: on Linux. Bug: 27923233 Change-Id: Ic16675650e4a8e138c163f1e2131a3aad7008ada
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
#define FLATBUFFERS_IDL_H_
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <stack>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
@@ -113,6 +112,7 @@ inline size_t SizeOf(BaseType t) {
|
||||
|
||||
struct StructDef;
|
||||
struct EnumDef;
|
||||
struct Parser;
|
||||
|
||||
// Represents any type in the IDL, which is a combination of the BaseType
|
||||
// and additional information for vectors/structs_.
|
||||
@@ -184,10 +184,8 @@ template<typename T> class SymbolTable {
|
||||
return it == dict.end() ? nullptr : it->second;
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<std::string, T *> dict; // quick lookup
|
||||
|
||||
public:
|
||||
std::map<std::string, T *> dict; // quick lookup
|
||||
std::vector<T *> vec; // Used to iterate in order of insertion
|
||||
};
|
||||
|
||||
@@ -208,6 +206,11 @@ struct Definition {
|
||||
Definition() : generated(false), defined_namespace(nullptr),
|
||||
serialized_location(0), index(-1) {}
|
||||
|
||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<
|
||||
reflection::KeyValue>>>
|
||||
SerializeAttributes(FlatBufferBuilder *builder,
|
||||
const Parser &parser) const;
|
||||
|
||||
std::string name;
|
||||
std::string file;
|
||||
std::vector<std::string> doc_comment;
|
||||
@@ -223,8 +226,8 @@ struct Definition {
|
||||
struct FieldDef : public Definition {
|
||||
FieldDef() : deprecated(false), required(false), key(false), padding(0) {}
|
||||
|
||||
Offset<reflection::Field> Serialize(FlatBufferBuilder *builder, uint16_t id)
|
||||
const;
|
||||
Offset<reflection::Field> Serialize(FlatBufferBuilder *builder, uint16_t id,
|
||||
const Parser &parser) const;
|
||||
|
||||
Value value;
|
||||
bool deprecated; // Field is allowed to be present in old data, but can't be
|
||||
@@ -250,7 +253,8 @@ struct StructDef : public Definition {
|
||||
if (fields.vec.size()) fields.vec.back()->padding = padding;
|
||||
}
|
||||
|
||||
Offset<reflection::Object> Serialize(FlatBufferBuilder *builder) const;
|
||||
Offset<reflection::Object> Serialize(FlatBufferBuilder *builder,
|
||||
const Parser &parser) const;
|
||||
|
||||
SymbolTable<FieldDef> fields;
|
||||
bool fixed; // If it's struct, not a table.
|
||||
@@ -299,7 +303,8 @@ struct EnumDef : public Definition {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Offset<reflection::Enum> Serialize(FlatBufferBuilder *builder) const;
|
||||
Offset<reflection::Enum> Serialize(FlatBufferBuilder *builder,
|
||||
const Parser &parser) const;
|
||||
|
||||
SymbolTable<EnumVal> vals;
|
||||
bool is_union;
|
||||
@@ -406,18 +411,18 @@ class Parser {
|
||||
anonymous_counter(0) {
|
||||
// Just in case none are declared:
|
||||
namespaces_.push_back(new Namespace());
|
||||
known_attributes_.insert("deprecated");
|
||||
known_attributes_.insert("required");
|
||||
known_attributes_.insert("key");
|
||||
known_attributes_.insert("hash");
|
||||
known_attributes_.insert("id");
|
||||
known_attributes_.insert("force_align");
|
||||
known_attributes_.insert("bit_flags");
|
||||
known_attributes_.insert("original_order");
|
||||
known_attributes_.insert("nested_flatbuffer");
|
||||
known_attributes_.insert("csharp_partial");
|
||||
known_attributes_.insert("stream");
|
||||
known_attributes_.insert("idempotent");
|
||||
known_attributes_["deprecated"] = true;
|
||||
known_attributes_["required"] = true;
|
||||
known_attributes_["key"] = true;
|
||||
known_attributes_["hash"] = true;
|
||||
known_attributes_["id"] = true;
|
||||
known_attributes_["force_align"] = true;
|
||||
known_attributes_["bit_flags"] = true;
|
||||
known_attributes_["original_order"] = true;
|
||||
known_attributes_["nested_flatbuffer"] = true;
|
||||
known_attributes_["csharp_partial"] = true;
|
||||
known_attributes_["stream"] = true;
|
||||
known_attributes_["idempotent"] = true;
|
||||
}
|
||||
|
||||
~Parser() {
|
||||
@@ -528,6 +533,8 @@ private:
|
||||
std::map<std::string, bool> included_files_;
|
||||
std::map<std::string, std::set<std::string>> files_included_per_file_;
|
||||
|
||||
std::map<std::string, bool> known_attributes_;
|
||||
|
||||
IDLOptions opts;
|
||||
|
||||
private:
|
||||
@@ -541,8 +548,6 @@ private:
|
||||
|
||||
std::vector<std::pair<Value, FieldDef *>> field_stack_;
|
||||
|
||||
std::set<std::string> known_attributes_;
|
||||
|
||||
int anonymous_counter;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user