clarification on Protobuf Bytestring Java Apis

I am looking for some clarification on Protobuf Bytestring Apis. I have a ByteString and i need to convert to a nio ByteBuffer or to a byte[] without having to perform a copy of underlying bytes .

toByteArray() method seems to perform a copy of bytes from backing array. Is this right

asReadOnlyByteBuffer() method in ByteString class. JavaDoc says The result uses the same backing array as the byte string, if possible. can someone clarify when the bytes copy will happen and when same backing array would get reused if i use asReadOnlyByteBuffer() method.

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.