Giter Site home page Giter Site logo

Byte Abstraction about rsocket-java HOT 8 CLOSED

rsocket avatar rsocket commented on May 8, 2024
Byte Abstraction

from rsocket-java.

Comments (8)

benjchristensen avatar benjchristensen commented on May 8, 2024

cc @NiteshKant as this is similar to what we have been discussing for ReactiveIPC.

from rsocket-java.

benjchristensen avatar benjchristensen commented on May 8, 2024

@tmontgomery and I were discussing the approach used in Agrona that Aeron uses.

from rsocket-java.

tmontgomery avatar tmontgomery commented on May 8, 2024

Will have to see if Agrona UnsafeBuffer can wrap a Netty ByteBuf. That would be the easiest if possible.

from rsocket-java.

NiteshKant avatar NiteshKant commented on May 8, 2024

If the intended buffer API in reactive socket is an interface, then I think i can make netty work in a way that instead of netty's ByteBuf we can have a ByteBuf impl that additionally implement our interface and we don't need to do an additional object allocation for wrapping per ByteBuf use.

from rsocket-java.

tmontgomery avatar tmontgomery commented on May 8, 2024

I think there are two pretty viable options. Agrona has a read-only and a read-write interface for accessing by index into a buffer. The interfaces are:

Implementing a concrete class for MutableDirectBuffer to netty ByteBuf should be straight forward.

Alternatively, it might be easy to add a new wrap function for UnsafeBuffer that can take a ByteBuf. This is simpler and also provides all the concurrent operations as well.

Either of these is pretty straight forward to do and gives appropriate data layout access.

from rsocket-java.

NiteshKant avatar NiteshKant commented on May 8, 2024

I see this Buffer abstraction we will have, show up in a few places:

  • Inside the currently existing Message abstraction to get the frame data.
  • Inside the client/server protocol classes for initiating different request types in some form.
  • For any generic encoder/decoder we write. eg: we will write an encoder/decoder for the payload data which will help to be generic, irrespective of which underneath network library we use.

Thus, I see the usage to be internal and external and so I would say we do not use an external library (agrona in this case) to represent that abstraction. We can pick the methods that makes sense from agrona and netty and define a Buffer abstraction which can eventually be defined in ReactiveIPC.

Once we have this interface, it is certainly possible to have an implementation for netty which will eliminate copying or wrapping of the underlying ByteBuf per use.

from rsocket-java.

tmontgomery avatar tmontgomery commented on May 8, 2024

Whether it be Agrona or not, it will need to support a few things for completeness (learned from developing Agrona buffers):

  • means to wrap with no allocation:
    • byte[] (part of interface)
    • java.nio.ByteBuffer (including direct) (part of interface)
    • netty ByteBuf (left to concrete impl)
    • Optional: off-heap array (left to concrete impl)
  • ByteOrdering optionality with nativeOrder default. (part of interface)
  • Java primitives (int, long, float, double) at an arbitrary index. (part of interface)
  • buffer put/get at an arbitrary index to/from any form supported by wrap above. (part of interface)
  • String encode/decode at an arbitrary index with length ByteOrder. (part of interface)
  • Optional: access via Unsafe and ability to disable per access bounds checks.

from rsocket-java.

benjchristensen avatar benjchristensen commented on May 8, 2024

We chose ByteBuffer for better-or-worse.

from rsocket-java.

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.