Multiple root_type in one IDL file

1,400 views
Skip to first unread message

Andrey Upadyshev

unread,
Sep 17, 2014, 6:58:13 AM9/17/14
to flatb...@googlegroups.com
Hello!

When I add more than one root_type declaration, the compiler generates special functions (GetXXX etc) for last root type only.
Is it a bug?

Thank you,
Andrey


Wouter van Oortmerssen

unread,
Sep 17, 2014, 12:29:33 PM9/17/14
to Andrey Upadyshev, flatb...@googlegroups.com
It's a bug in the sense that it should give an error. A single file can only have one root type.
You can still use the other types as root types if you want by calling the templated GetRoot<> function, however.
I should document this better.

--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrey Upadyshev

unread,
Sep 18, 2014, 12:19:53 PM9/18/14
to Wouter van Oortmerssen, flatb...@googlegroups.com
Hello Wouter,

Is there a significant reason for limitation to have only one root_type per file? Probably it's better to allow to have multiple root_types because otherwise protocol definition must be spread into several files (or don't use helper functions at all).

Best Regards,
Andrey

Wouter van Oortmerssen

unread,
Sep 18, 2014, 12:35:34 PM9/18/14
to Andrey Upadyshev, flatb...@googlegroups.com
the root_type is mainly for use with JSON, since there you need to know what the root type is to be able to parse it. Like I said, in C++ you don't really need the generated helper functions, you can use GetRoot<> on any type.

Andrey Upadyshev

unread,
Sep 18, 2014, 12:49:31 PM9/18/14
to Wouter van Oortmerssen, flatb...@googlegroups.com
Using of GetRoot<> is OK for me.

I just want to point to some inconsistency: if root_type is not important and everything can be done without using of it, why to have it at all? And if it required for something (I can not realize what it can be) then why restrict the ability to define more then one root object in one FBS file. If there is more than one root_object defined then user can just pick up one it needs in every specific case.

Best Regards
Reply all
Reply to author
Forward
0 new messages