Git Product home page Git Product logo

Comments (10)

 avatar commented on April 28, 2024

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.

from flatbuffers.

lbensaad avatar lbensaad commented on April 28, 2024

Ok, thanks. But in Java,

  1. If i have a ByteBuffer of a non root table how do read that using FlatBuffersBuilder. The only way I know is to use the __init() function, is there another way?
  2. Is there a way to know the type of the table from the binary data?
  3. How to use the addXXXType function, in your JavaTest.java you used: Monster.addTestType(fbb, (byte)1); how do you get the type of a table, in this case 1 which it is hard-coded ?

from flatbuffers.

 avatar commented on April 28, 2024
  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.

from flatbuffers.

lbensaad avatar lbensaad commented on April 28, 2024

Thanks

  1. But i think the name should be just "get" or "init" instead of getRootAs

from flatbuffers.

 avatar commented on April 28, 2024

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.

from flatbuffers.

let4be avatar let4be commented on April 28, 2024

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

from flatbuffers.

let4be avatar let4be commented on April 28, 2024

Tried both latest master and latest release versions

from flatbuffers.

 avatar commented on April 28, 2024

In C++ there is the GetRoot templated function that works with any table type.
Go appears to still be pending on: #363

from flatbuffers.

gaurimaheshwari avatar gaurimaheshwari commented on April 28, 2024

please explain me how to build flatc executable?

from flatbuffers.

aardappel avatar aardappel commented on April 28, 2024

@gaurimaheshwari : https://google.github.io/flatbuffers/flatbuffers_guide_building.html

from flatbuffers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.