The ByteArray type uses protobuf's ByteString under the hood, but doesn't allow an outside user to turn a ByteString into a ByteArray (or vice versa) without making an explicit copy. Given that both ByteString and ByteArray are immutable, I can't see a reason why this should not be possible. For example, a ByteArray.wrap(ByteString) and ByteArray.asByteString() method seem appropriate. Those would come in very handy when using the client libraries within a gRPC service.
Could someone please explain why this is the case? If there is no reason, I would be happy to open a PR. Thanks!
P.S. I did notice that the class is non-final and by subclassing one can expose the protected constructor and getByteString() method, but that seems silly.
The
ByteArraytype uses protobuf'sByteStringunder the hood, but doesn't allow an outside user to turn aByteStringinto aByteArray(or vice versa) without making an explicit copy. Given that bothByteStringandByteArrayare immutable, I can't see a reason why this should not be possible. For example, aByteArray.wrap(ByteString)andByteArray.asByteString()method seem appropriate. Those would come in very handy when using the client libraries within a gRPC service.Could someone please explain why this is the case? If there is no reason, I would be happy to open a PR. Thanks!
P.S. I did notice that the class is non-final and by subclassing one can expose the protected constructor and
getByteString()method, but that seems silly.