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.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eUnsafeByteOperations\u003c/code\u003e class provides methods for high-performance byte operations in advanced applications, directly interacting with the backing buffer of \u003ccode\u003eByteString\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThese methods are "unsafe" because they expose the backing buffer of a \u003ccode\u003eByteString\u003c/code\u003e, and modifying this buffer can cause application errors.\u003c/p\u003e\n"],["\u003cp\u003eModifying a \u003ccode\u003eByteString\u003c/code\u003e buffer after using \u003ccode\u003eUnsafeByteOperations\u003c/code\u003e may result in issues like serialization failures, incorrect serialization output, or the breaking of object immutability.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eUnsafeWrap\u003c/code\u003e method creates a \u003ccode\u003eByteString\u003c/code\u003e from provided bytes without copying, however the passed bytes must remain unchanged during the \u003ccode\u003eByteString\u003c/code\u003e's usage.\u003c/p\u003e\n"],["\u003cp\u003eThe latest version is \u003ccode\u003e3.27.1\u003c/code\u003e, there are also older versions available \u003ccode\u003e3.23.0\u003c/code\u003e and \u003ccode\u003e3.15.8\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,[]]