@ExperimentalApi public final class UnsafeByteOperations extends Object
ByteStringto the application.
DISCLAIMER: The methods in this class should only be called if it is
guaranteed that the buffer backing the
ByteString will never change! Mutation of a
ByteString can lead to unexpected and undesirable consequences in your application,
and will likely be difficult to debug. Proceed with caution!
This can have a number of significant side affects that have spooky-action-at-a-distance-like behavior. In particular, if the bytes value changes out from under a Protocol Buffer:
|Modifier and Type||Method and Description|
An unsafe operation that returns a
public static ByteString unsafeWrap(ByteBuffer buffer)
ByteStringthat is backed by the provided buffer.
buffer- the Java NIO buffer to be wrapped
ByteStringbacked by the provided buffer
public static void unsafeWriteTo(ByteString bytes, ByteOutput output) throws IOException
ByteStringto the provided
ByteOutput. Calling this method may result in multiple operations on the target
ByteOutput(i.e. for roped
This method exposes the internal backing buffer(s) of the
ByteString to the
ByteOutput in order to avoid additional copying overhead. It would be possible for a malicious
ByteOutput to corrupt the
ByteString. Use with caution!
ByteOutput MUST NOT modify the provided buffers. Doing
so may result in corrupted data, which would be difficult to debug.