public static class UnsafeByteOperations
Provides a number of unsafe byte operations to be used by advanced applications with high performance requirements. These methods are referred to as "unsafe" due to the fact that they potentially expose the backing buffer of a ByteString to the application.
Namespace
Google.ProtobufAssembly
Google.Protobuf.dll
Remarks
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:
- serialization may throw
- serialization may succeed but the wrong bytes may be written out
- objects that are normally immutable (such as ByteString) are no longer immutable
- hashCode may be incorrect
Methods
UnsafeWrap(ReadOnlyMemory<byte>)
public static ByteString UnsafeWrap(ReadOnlyMemory<byte> bytes)
Constructs a new ByteString from the given bytes. The bytes are not copied, and must not be modified while the ByteString is in use. This API is experimental and subject to change.
Parameter | |
---|---|
Name | Description |
bytes |
ReadOnlyMemorybyte |
Returns | |
---|---|
Type | Description |
ByteString |