Class UnsafeByteOperations

public static class UnsafeByteOperations : object

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.

Inheritance

Object > UnsafeByteOperations

Namespace

Google.Protobuf

Assembly

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
TypeNameDescription
ReadOnlyMemory<Byte>bytes
Returns
TypeDescription
ByteString