Git Product home page Git Product logo

Comments (11)

 avatar commented on April 28, 2024

Agreed, sounds like a good feature.

from flatbuffers.

lbensaad avatar lbensaad commented on April 28, 2024

Good, especially if this library is described as "Memory Efficient Serialization Library" so adding this feature should be a core feature, I also plan to use it with Netty which use pooling also.
It could be something like this:
public FlatBufferBuilder(ByteBuffer bb)
{
this.bb = bb;
this.bb.order(ByteOrder.LITTLE_ENDIAN);
space=this.bb.position();
}

from flatbuffers.

 avatar commented on April 28, 2024

why space=this.bb.position() ? FlatBuffers writes to ByteBuffers in an absolute way, and does not rely on position() being anywhere in particular. space represents the amount of space left over at the beginning of the buffer, so should be set to the size of the backing array at the start.

from flatbuffers.

 avatar commented on April 28, 2024

Just added such a constructor as part of the last commit.

from flatbuffers.

lbensaad avatar lbensaad commented on April 28, 2024

That is good, thank you,

from flatbuffers.

lbensaad avatar lbensaad commented on April 28, 2024

I see that you clear the Buffer before using it, what if the buffer contains other data? But i don't know if this is a possible scenario!

from flatbuffers.

 avatar commented on April 28, 2024

the clear() call only resets the writable area, it doesn't actually clear
the bytes. But yes, to create a FlatBuffer, you want to be using the entire
ByteBuffer, concatenating isn't supported.

from flatbuffers.

lbensaad avatar lbensaad commented on April 28, 2024

I think there is another problem with direct buffers, they don't have array(), and the FlatBufferBuilder uses it a lot so it will cause a problem.
I think you should throw UnsuportedOperationException if the the provided buffer has no array (make a call to hasArray() to know that)

from flatbuffers.

 avatar commented on April 28, 2024

ok, will add that.

from flatbuffers.

lbensaad avatar lbensaad commented on April 28, 2024
  1. It could be a better solution to use bb.capacity() instead of dd.array().length; I did a Replace All in my code editor and test it and it did work, you can do more testing.
  2. You should also avoid the use of bb.array() and System.arrayCopy like in fbb.growByteBuffer() and fbb.createString. You should use bb.put(byte[]) and bb.get(byte[]) instead.
  3. i think growByteBuffer() and newByteBuffer() should be static functions.

from flatbuffers.

 avatar commented on April 28, 2024
  1. I already did that.
  2. The reason I didn't use put and get is that there are no absolute versions of those calls available, meaning you need to explicitly set the position.. though I suppose that is no big deal.
  3. Agreed.

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.