Skip to content

feat: Add java.nio.ByteBuffer support to IonSystem - #1168

Open
brandontoner wants to merge 1 commit into
amazon-ion:masterfrom
brandontoner:master
Open

brandontoner wants to merge 1 commit into
amazon-ion:masterfrom
brandontoner:master

Conversation

@brandontoner

Copy link
Copy Markdown

Issue #, if available:

None

Description of changes:

Add ByteBuffer overloads to the three most common IonSystem entry points so callers holding NIO buffers no longer need to copy into a byte[] themselves:

  • IonSystem.iterate(ByteBuffer)
  • IonSystem.newReader(ByteBuffer)
  • IonSystem.singleValue(ByteBuffer)

The methods are declared as interface default methods that delegate to the existing byte[] overloads, so the addition is source- and binary-compatible for external IonSystem implementors. A shared helper, _Private_ByteBufferUtils.toByteArrayConsuming, copies the buffer's readable region ([position, limit)) via a relative bulk get, which works for array-backed, direct (off-heap), and read-only buffers alike and advances position to limit (consume semantics). The reader/iterator operates over a private copy, so later buffer mutations do not affect reading.

Add six FROM_BYTE_BUFFER_* constants to the ReaderMaker test enum (binary, text, direct, read-only, and sliced sub-range variants) so the shared reader suites exercise the new path, plus IonSystemByteBufferTest covering all buffer kinds, both formats, the position/limit contract, snapshot isolation, and null/EOF/multi-value error behavior.

This provides the base level functionality, this could be optimized in the future to directly access the backing array where possible to improve performance.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Add ByteBuffer overloads to the three most common IonSystem entry
points so callers holding NIO buffers no longer need to copy into a
byte[] themselves:

  - IonSystem.iterate(ByteBuffer)
  - IonSystem.newReader(ByteBuffer)
  - IonSystem.singleValue(ByteBuffer)

The methods are declared as interface default methods that delegate to
the existing byte[] overloads, so the addition is source- and
binary-compatible for external IonSystem implementors. A shared helper,
_Private_ByteBufferUtils.toByteArrayConsuming, copies the buffer's
readable region ([position, limit)) via a relative bulk get, which works
for array-backed, direct (off-heap), and read-only buffers alike and
advances position to limit (consume semantics). The reader/iterator
operates over a private copy, so later buffer mutations do not affect
reading.

Add six FROM_BYTE_BUFFER_* constants to the ReaderMaker test enum
(binary, text, direct, read-only, and sliced sub-range variants) so the
shared reader suites exercise the new path, plus IonSystemByteBufferTest
covering all buffer kinds, both formats, the position/limit contract,
snapshot isolation, and null/EOF/multi-value error behavior.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant