diff options
author | Mitchel <mitchellabonte@hotmail.com> | 2018-02-23 17:01:05 -0500 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2018-02-23 14:01:05 -0800 |
commit | 55ddb84eb26e974aee31ddaad47ad0c7aaf382dd (patch) | |
tree | 2ae508a9eb5f1ba90d844d535a8e625a78bc96c7 /java | |
parent | 6e2e909b5c9737ec169ddbdb9ed9b8aa2e908aa1 (diff) | |
download | flatbuffers-55ddb84eb26e974aee31ddaad47ad0c7aaf382dd.tar.gz flatbuffers-55ddb84eb26e974aee31ddaad47ad0c7aaf382dd.tar.bz2 flatbuffers-55ddb84eb26e974aee31ddaad47ad0c7aaf382dd.zip |
In Java, allow reusing ByteBuffer in getters (#4633)
* In Java, allow reusing ByteBuffer in getters
* In Java, allow reusing ByteBuffer in getters
* In Java, allow reusing ByteBuffer in getters
Diffstat (limited to 'java')
-rw-r--r-- | java/com/google/flatbuffers/Table.java | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/java/com/google/flatbuffers/Table.java b/java/com/google/flatbuffers/Table.java index 6199ed40..cbbeda11 100644 --- a/java/com/google/flatbuffers/Table.java +++ b/java/com/google/flatbuffers/Table.java @@ -173,6 +173,27 @@ public class Table { } /** + * Initialize vector as a ByteBuffer. + * + * This is more efficient than using duplicate, since it doesn't copy the data + * nor allocattes a new {@link ByteBuffer}, creating no garbage to be collected. + * + * @param bb The {@link ByteBuffer} for the array + * @param vector_offset The position of the vector in the byte buffer + * @param elem_size The size of each element in the array + * @return The {@link ByteBuffer} for the array + */ + protected ByteBuffer __vector_in_bytebuffer(ByteBuffer bb, int vector_offset, int elem_size) { + int o = this.__offset(vector_offset); + if (o == 0) return null; + int vectorstart = __vector(o); + bb.rewind(); + bb.limit(vectorstart + __vector_len(o) * elem_size); + bb.position(vectorstart); + return bb; + } + + /** * Initialize any Table-derived type to point to the union at the given `offset`. * * @param t A `Table`-derived type that should point to the union at `offset`. |