Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@fbenkstein
Copy link
Contributor

This adds support for using a binary schema created with flatc --binary --schema as in input for JSON serialization and deserialization. This is useful since a binary schema can be stored as a single object without having to deal with include paths. Ultimately, it might be useful to be able to use a binary schema to generate code as well but I don't know if it's really worth it. This is still a work in progress at the moment as I've only added one test which doesn't even pass. I've already found one problem, though: by default builtin attributes are not serialized which means that flexbuffer [ubyte] members don't work unless --bfbs-builtins is also specified. I think the same is true for nested_flatbuffer but I'm not that far yet. @aardappel Should we extend the reflection::Field with a flexbuffer:bool and nested_flatbuffer:string?

fbenkstein and others added 2 commits October 14, 2018 09:01
std::function makes code harder to debug because it requires stepping
through a separate destructor and call operator.  It's use unnecessary
in the Parser since the functions taking functors are private and are
only used within idl_parser.cpp.  Therefore the definitions can stay in
idl_parser.cpp as well.  Only care must be taken that the definitions
appear before use but that's already true and all compilers will
complain equally if it get's violated.  This change might also improve
performance since it might allow inlining where it wasn't possible
before but I haven't measured that.
Support binary schemas in flatc and flatbuffers::Parser.  This can
simplify loading JSON data in some cases since there's no issue with
include files.
@aardappel
Copy link
Collaborator

Yes, I think the big issue is that binary schemas were never intended to have the full set of information that the parser stores, as they initially were only needed for reflection.

We could add more data to the reflection data to have the full coverage the JSON and language code-gens need.. I am just afraid it is going to clutter the schema a lot. For that reason, for most bools that are derived from attributes, I'd say store those as attributes and only turn them back into bools upon reading them back into the parser state. I know that uses way more space, but is probably acceptable for attributes that are used infrequently.

Copy link
Collaborator

@aardappel aardappel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally very nice functionality! Can you document somewhere how this can be used? This could be either in CppUsage.md in the reflection section, and/or somewhere in Schemas.md


Offset<reflection::Field> Serialize(FlatBufferBuilder *builder, uint16_t id,
const Parser &parser) const;
bool Deserialize(const reflection::Field* field, Parser& parser);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the existing code style for *.

size_t parent_fieldn,
const StructDef *parent_struct_def);
// clang-format off
#if defined(FLATBUFFERS_CPP98_STL)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rebase?

" --raw-binary Allow binaries without file_indentifier to be read.\n"
" This may crash flatc given a mismatched schema.\n"
" --size-prefixed Input binaries are size prefixed buffers.\n"
" --schema-size-prefixed\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not reuse the existing flag for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is that with flatc --schema --binary --size-prefixed a size prefixed schema is created. Now if you want to read or create a plain buffer with a size prefixed schema or a size prefixed buffer with a plain schema you need flags to tell which is which. I imagine that the size-prefixed schema case itself is rare so you rarely ever need to give this flag.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, makes sense.

if (schema->services()) {
for (auto it = schema->services()->begin(); it != schema->services()->end();
++it) {
std::string qualified_name = it->name()->str();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use auto where possible.

@fbenkstein
Copy link
Contributor Author

I don't I'll be able to finish this PR — at least not any time soon. I can leave it open if anybody else wants to pick it up.

@aardappel
Copy link
Collaborator

There is now a second PR trying to do the same: #5077
Can you compare?

@aardappel aardappel force-pushed the master branch 3 times, most recently from f381fd7 to 31f8799 Compare December 26, 2019 20:37
@aardappel aardappel force-pushed the master branch 5 times, most recently from f116b80 to f12cca8 Compare May 5, 2020 20:57
@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2020

This pull request is stale because it has been open 6 months with no activity. Please comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Nov 4, 2020
@github-actions github-actions bot closed this Nov 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants