aboutsummaryrefslogtreecommitdiff
path: root/include/flatbuffers/idl.h
diff options
context:
space:
mode:
authortira-misu <tmisu@gmx.de>2018-12-13 20:59:27 +0100
committerWouter van Oortmerssen <aardappel@gmail.com>2018-12-13 11:59:27 -0800
commitdba962ebb836739e002049a6d484f54a176e9afe (patch)
treefaf803f2d8b826a77be2b3b4368ade225486161b /include/flatbuffers/idl.h
parent60a0f35fbc43e578ffa2ea06c2956380a4bff10b (diff)
downloadflatbuffers-dba962ebb836739e002049a6d484f54a176e9afe.tar.gz
Enable flatbuffer to initialize Parser from bfbs (#4283) (#5077)
* Enable flatbuffer to initialize Parser from bfbs (#4283) Now its possible to generate json data from bfbs data type and flatbuffers data and visa versa. * add deserialize functionality in parser from bfbs * add small usage sample * Fix build break * Merge branch 'pr/1' into fix-issue4283 * Fix buildbreak * Build monster_test.bfbs with --bfbs-builtins Attribute flexbuffer has be included in bfbs. Only with this attribute test will run. By initialization a parser by a bfbs the attribute has to be known for this filed. monsterdata_test.golden has a flexbuffer field so parse would fail. * Fix generate_code.sh * Revert automatic indent changes by IDE * Auto detect size prefixed binary schema files * Use identifier (bfbs) to detect schema files
Diffstat (limited to 'include/flatbuffers/idl.h')
-rw-r--r--include/flatbuffers/idl.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h
index 18e1db9d..00e6af5e 100644
--- a/include/flatbuffers/idl.h
+++ b/include/flatbuffers/idl.h
@@ -153,6 +153,8 @@ struct Type {
Offset<reflection::Type> Serialize(FlatBufferBuilder *builder) const;
+ bool Deserialize(const Parser &parser, const reflection::Type *type);
+
BaseType base_type;
BaseType element; // only set if t == BASE_TYPE_VECTOR
StructDef *struct_def; // only set if t or element == BASE_TYPE_STRUCT
@@ -235,6 +237,9 @@ struct Definition {
flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>>>
SerializeAttributes(FlatBufferBuilder *builder, const Parser &parser) const;
+ bool DeserializeAttributes(Parser &parser,
+ const Vector<Offset<reflection::KeyValue>> *attrs);
+
std::string name;
std::string file;
std::vector<std::string> doc_comment;
@@ -261,6 +266,8 @@ struct FieldDef : public Definition {
Offset<reflection::Field> Serialize(FlatBufferBuilder *builder, uint16_t id,
const Parser &parser) const;
+ bool Deserialize(Parser &parser, const reflection::Field *field);
+
Value value;
bool deprecated; // Field is allowed to be present in old data, but can't be.
// written in new data nor accessed in new code.
@@ -291,6 +298,8 @@ struct StructDef : public Definition {
Offset<reflection::Object> Serialize(FlatBufferBuilder *builder,
const Parser &parser) const;
+ bool Deserialize(Parser &parser, const reflection::Object *object);
+
SymbolTable<FieldDef> fields;
bool fixed; // If it's struct, not a table.
@@ -317,9 +326,12 @@ inline size_t InlineAlignment(const Type &type) {
struct EnumVal {
EnumVal(const std::string &_name, int64_t _val) : name(_name), value(_val) {}
+ EnumVal(){};
Offset<reflection::EnumVal> Serialize(FlatBufferBuilder *builder, const Parser &parser) const;
+ bool Deserialize(const Parser &parser, const reflection::EnumVal *val);
+
std::string name;
std::vector<std::string> doc_comment;
int64_t value;
@@ -340,6 +352,8 @@ struct EnumDef : public Definition {
Offset<reflection::Enum> Serialize(FlatBufferBuilder *builder, const Parser &parser) const;
+ bool Deserialize(Parser &parser, const reflection::Enum *values);
+
SymbolTable<EnumVal> vals;
bool is_union;
// Type is a union which uses type aliases where at least one type is
@@ -358,11 +372,14 @@ inline bool EqualByName(const Type &a, const Type &b) {
struct RPCCall : public Definition {
Offset<reflection::RPCCall> Serialize(FlatBufferBuilder *builder, const Parser &parser) const;
+ bool Deserialize(Parser &parser, const reflection::RPCCall *call);
+
StructDef *request, *response;
};
struct ServiceDef : public Definition {
Offset<reflection::Service> Serialize(FlatBufferBuilder *builder, const Parser &parser) const;
+ bool Deserialize(Parser &parser, const reflection::Service *service);
SymbolTable<RPCCall> calls;
};
@@ -647,6 +664,15 @@ class Parser : public ParserState {
// See reflection/reflection.fbs
void Serialize();
+ // Deserialize a schema buffer
+ bool Deserialize(const uint8_t *buf, const size_t size);
+
+ // Fills internal structure as if the schema passed had been loaded by parsing
+ // with Parse except that included filenames will not be populated.
+ bool Deserialize(const reflection::Schema* schema);
+
+ Type* DeserializeType(const reflection::Type* type);
+
// Checks that the schema represented by this parser is a safe evolution
// of the schema provided. Returns non-empty error on any problems.
std::string ConformTo(const Parser &base);
@@ -661,6 +687,8 @@ class Parser : public ParserState {
StructDef *LookupStruct(const std::string &id) const;
+ std::string UnqualifiedName(std::string fullQualifiedName);
+
private:
void Message(const std::string &msg);
void Warning(const std::string &msg);