-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Enable flatbuffer to initialize Parser from bfbs (#4283) #5077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
|
I signed it! |
|
CLAs look good, thanks! |
include/flatbuffers/idl.h
Outdated
| Offset<reflection::Object> Serialize(FlatBufferBuilder *builder, | ||
| const Parser &parser) const; | ||
|
|
||
| void Deserialize(Parser *parser, const flatbuffers::Vector<flatbuffers::Offset<reflection::Field>> *flatFields); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use snake_case, not camelCase, here and elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, lines <80 chars, { on same line.. please read Google C++ Style Guide and apply to your code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is now Google C++ Style Guide conform.
|
|
||
| using namespace MyGame::Sample; | ||
|
|
||
| // This is an example of parsing text straight into a buffer and then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate that you've made a sample, but really this would be better off in the tests, since these samples are not run as part of testing. Also, would be better to use the existing .bfbs file rather than generating it anew.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using existing bfbs in example now.
Used/fixed existing test of @fbenkstein. (And found/fixed some issues in deserialization)
| std::string Parser::GetNameFromFullQualifiedName(std::string fullQualifiedName) | ||
| { | ||
| Namespace *ns = new Namespace(); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no empty lines needed, unless function is really long.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
|
Thanks! This looks like a pretty good implementation, but how is it different from #5001 by @fbenkstein ? Could you two compare implementations and make sure we end up with the best of both somehow? |
|
I will pick up @fbenkstein implementation and merge it into mine. It seams that he has no time for it. I wasn't aware that someone had already taken on the subject. |
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.
src/flatc.cpp
Outdated
| " --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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend not having this option. Having 2 kinds of binary schema files doesn't help anyone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem is, you already have two kinds of schema files, depending whether you call flatc --binary --schema with the --size-prefixed option or not. In #5001 I added the flag so you can serialize and deserialize with or without size prefix independently of whether your schema is size prefixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compromise: removing this option and allow both file formats. Binary will be verified against both verifier and right one will be choosen. What's your opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the verifier to decide doesn't sound great, better would be to use reflection::SchemaBufferHasIdentifier, and when that fails, try again assuming the first 4 bytes are a size.
I guess to me --size-prefixed is a niche feature, so --schema-size-prefixed is a niche of niche, and would prefer to not polute the options with it if we can reasonably either demand only regular FlatBuffers are used for binary schemas, or silently detect both with the above option.
src/idl_parser.cpp
Outdated
| const auto repack = IsInteger(e.type.base_type); | ||
| switch (e.type.base_type) { | ||
| // clang-format off | ||
| // clang-format off |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're going to indent the comment, then also the code following it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn IDE. It has changed some points of its own. I hoped that I reverted all, but somehow i missed something. I will look through all changes again an fix it.
|
Yes. Makes sense.
…On Mon 10. Dec 2018 at 21:46 Wouter van Oortmerssen < ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/flatc.cpp
<#5077 (comment)>:
> @@ -106,6 +125,8 @@ std::string FlatCompiler::GetUsageString(const char *program_name) const {
" --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"
Using the verifier to decide doesn't sound great, better would be to use
reflection::SchemaBufferHasIdentifier, and when that fails, try again
assuming the first 4 bytes are a size.
I guess to me --size-prefixed is a niche feature, so
--schema-size-prefixed is a niche of niche, and would prefer to not
polute the options with it if we can reasonably either demand only regular
FlatBuffers are used for binary schemas, or silently detect both with the
above option.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5077 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHXSIyCdWrjQ5TmSF7cP436UOjd_geSdks5u3sgogaJpZM4Y98Nt>
.
|
|
Thanks, looking good now! |
…e#5077) * Enable flatbuffer to initialize Parser from bfbs (google#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
Now its possible to generate json data from bfbs data type and flatbuffers data
and visa versa.
Thank you for submitting a PR!
Please make sure you include the names of the affected language(s) in your PR title.
This helps us get the correct maintainers to look at your issue.
If you make changes to any of the code generators, be sure to run
cd tests && sh generate_code.sh(or equivalent .bat) and include the generatedcode changes in the PR. This allows us to better see the effect of the PR.
If your PR includes C++ code, please adhere to the Google C++ Style Guide,
and don't forget we try to support older compilers (e.g. VS2010, GCC 4.6.3),
so only some C++11 support is available.
Include other details as appropriate.
Thanks!