Closed lbensaad closed 10 years ago
Any table can be a root in a buffer. The root type is mostly for use by JSON, which doesn't specify any types, so we need to know where to start. The generated GetRoot functions are merely convenience.
Ok, thanks. But in Java,
1) a commit was pushed yesterday that adds GetRootAs functions for all tables, not just the root_type.
2) generally no. this is a strongly types system, meaning you need to know the kind of buffer you're dealing with. If you want to use this in a context where you want to have multiple different root types, you have these options: a) make your root type a table that contains a union of all possible sub-roots. b) prefix flatbuffers with your own file header c) use flatbuffer's built-in file indentification feature, which hasn't been ported to Java yet. I'll get to that.
3) That's a bug, the 1
should actually read: Any.Monster
. I'll fix that.
Thanks 1) But i think the name should be just "get" or "init" instead of getRootAs
getRootAs
is a bit more descriptive and less likely to clash with other identifiers. I think I'll keep it for now.
To further my response to your issue #2, the built-in file_identifier functionality is now also available in Java. See the Schema docs, Java docs, and Java code.
So... How do I access non root_type buffers, can't find anything like Get*\ in c++ generated files and the same problem in go lang. generated code has huge differencies between languages and it's really hard to work with
Tried both latest master and latest release versions
In C++ there is the GetRoot
please explain me how to build flatc executable?
@gaurimaheshwari : https://google.github.io/flatbuffers/flatbuffers_guide_building.html
What is the reason of using a root type. If i have Request and Response tables to be sent between two parties, so why we could not create them separately. A buffer could contain either a Request or a Response. In fact any message(Table) should be able to a root in a buffer.