java icon indicating copy to clipboard operation
java copied to clipboard

Allow use of ByteBuffer for underlying data

Open quom opened this issue 7 years ago • 2 comments

It would be useful to be able to use a ByteBuffer rather than a byte[] to read data from. When using ByteBuffer.allocateDirect there is no underlying byte[] to access and call reset on the JsonIterator object.

The incoming data might be memory mapped to a network card buffer (i.e. off-heap) and therefore would allow zero copy parsing. Currently I am having to copy the data into an on-heap byte array before calling parse.

quom avatar Jan 02 '18 13:01 quom

sounds valid. Would you like to contribute a pull request?

taowen avatar Jan 02 '18 23:01 taowen

I'll see if I can find some time to do it.

Is there any way to do zero allocation binding too? I'd like to be able to use static code gen decoding to bind to an object that has CharBuffers in place of string fields. I looked at using slice for this but it looks like the iterator reuses the same slice object and assigns objects before calling set/binding so all fields with type Slice refer to the same object.

quom avatar Jan 31 '18 11:01 quom