diff --git a/runtime/src/main/java/org/capnproto/Data.java b/runtime/src/main/java/org/capnproto/Data.java index 81cabb3..9dab3b0 100644 --- a/runtime/src/main/java/org/capnproto/Data.java +++ b/runtime/src/main/java/org/capnproto/Data.java @@ -82,7 +82,7 @@ public final class Data { return this.size; } - public ByteBuffer toByteBuffer() { + public ByteBuffer asByteBuffer() { ByteBuffer dup = this.buffer.asReadOnlyBuffer(); dup.position(this.offset); ByteBuffer result = dup.slice(); @@ -110,6 +110,14 @@ public final class Data { this.size = size; } + public ByteBuffer asByteBuffer() { + ByteBuffer dup = this.buffer.duplicate(); + dup.position(this.offset); + ByteBuffer result = dup.slice(); + result.limit(this.size); + return result; + } + public byte[] toArray() { ByteBuffer dup = this.buffer.duplicate(); byte result[] = new byte[this.size]; diff --git a/runtime/src/main/java/org/capnproto/Text.java b/runtime/src/main/java/org/capnproto/Text.java index d65c86a..fa67524 100644 --- a/runtime/src/main/java/org/capnproto/Text.java +++ b/runtime/src/main/java/org/capnproto/Text.java @@ -91,7 +91,7 @@ public final class Text { return this.size; } - public ByteBuffer toByteBuffer() { + public ByteBuffer asByteBuffer() { ByteBuffer dup = this.buffer.asReadOnlyBuffer(); dup.position(this.offset); ByteBuffer result = dup.slice(); @@ -127,6 +127,14 @@ public final class Text { this.size = size; } + public ByteBuffer asByteBuffer() { + ByteBuffer dup = this.buffer.duplicate(); + dup.position(this.offset); + ByteBuffer result = dup.slice(); + result.limit(this.size); + return result; + } + @Override public final String toString() { byte[] bytes = new byte[this.size];