On Mon, Aug 30, 2010 at 20:28, Bryan Duxbury (JIRA) <[email protected]> wrote: > > [ > https://issues.apache.org/jira/browse/THRIFT-872?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12904274#action_12904274 > ] > > Bryan Duxbury commented on THRIFT-872: > -------------------------------------- > > What about making TProtocol's readBinary method non-abstract like this: > > {code} > public final byte[] readBytes() { > ByteBuffer buf = readBinary(); > byte[] bytes = new byte[buf.capacity()]; > buf.get(buf); > return buf; > } > {code}
allocating buf.capacity() will allocate too many bytes. I also assume it should read buf.read(bytes) and return bytes. It is also needed to determine the semantics we want for the byte buffers compared to the old byte[], is it the backing array's content or the content between position and limit()? If position is taken into account, the above method is not idempotent, two calls won't return the same array content as the call to get moves the position. Mathias.
