Struct FastBufferWriter
Optimized class used for writing values into a byte stream FastBufferReader BytePacker ByteUnpacker
Implements
Inherited Members
Namespace: Unity.Netcode
Assembly: solution.dll
Syntax
public struct FastBufferWriter : IDisposable
Constructors
Name | Description |
---|---|
FastBufferWriter(int, Allocator, int) | Create a FastBufferWriter. |
Properties
Name | Description |
---|---|
Capacity | The current total buffer size |
IsInitialized | Gets a value indicating whether the writer has been initialized and a handle allocated. |
Length | The total amount of bytes that have been written to the stream |
MaxCapacity | The maximum possible total buffer size |
Position | The current write position |
Methods
Name | Description |
---|---|
CopyFrom(FastBufferWriter) | Copy the contents of another writer into this writer. The contents will be copied from the beginning of the other writer to its current position. They will be copied to this writer starting at this writer's current position. |
CopyTo(FastBufferWriter) | Copy the contents of this writer into another writer. The contents will be copied from the beginning of this writer to its current position. They will be copied to the other writer starting at the other writer's current position. |
Dispose() | IDisposable implementation that frees the allocated buffer |
EnterBitwiseContext() | Retrieve a BitWriter to be able to perform bitwise operations on the buffer. No bytewise operations can be performed on the buffer until bitWriter.Dispose() has been called. At the end of the operation, FastBufferWriter will remain byte-aligned. |
GetUnsafePtr() | Gets a direct pointer to the underlying buffer |
GetUnsafePtrAtCurrentPosition() | Gets a direct pointer to the underlying buffer at the current read position |
GetWriteSize(string, bool) | Get the required size to write a string |
GetWriteSize<T>() | Get the size required to write an unmanaged value of type T |
GetWriteSize<T>(NativeArray<T>, int, int) | Get the required size to write a NativeArray |
GetWriteSize<T>(in NativeArray<T>) | Get the write size for an array of FixedStrings |
GetWriteSize<T>(in T) | Get the write size for a FixedString |
GetWriteSize<T>(in T, ForStructs) | Get the write size for any general unmanaged value The ForStructs value here makes this the lowest-priority overload so other versions will be prioritized over this if they match |
GetWriteSize<T>(T[], int, int) | Get the required size to write an unmanaged array |
Seek(int) | Move the write position in the stream. Note that moving forward past the current length will extend the buffer's Length value even if you don't write. |
ToArray() | Returns an array representation of the underlying byte buffer. !!Allocates a new array!! |
Truncate(int) | Truncate the stream by setting Length to the specified value. If Position is greater than the specified value, it will be moved as well. |
TryBeginWrite(int) | Allows faster serialization by batching bounds checking. When you know you will be writing multiple fields back-to-back and you know the total size, you can call TryBeginWrite() once on the total size, and then follow it with calls to WriteValue() instead of WriteValueSafe() for faster serialization. Unsafe write operations will throw OverflowException in editor and development builds if you go past the point you've marked using TryBeginWrite(). In release builds, OverflowException will not be thrown for performance reasons, since the point of using TryBeginWrite is to avoid bounds checking in the following operations in release builds. |
TryBeginWriteInternal(int) | Internal version of TryBeginWrite. Differs from TryBeginWrite only in that it won't ever move the AllowedWriteMark backward. |
TryBeginWriteValue<T>(in T) | Allows faster serialization by batching bounds checking. When you know you will be writing multiple fields back-to-back and you know the total size, you can call TryBeginWrite() once on the total size, and then follow it with calls to WriteValue() instead of WriteValueSafe() for faster serialization. Unsafe write operations will throw OverflowException in editor and development builds if you go past the point you've marked using TryBeginWrite(). In release builds, OverflowException will not be thrown for performance reasons, since the point of using TryBeginWrite is to avoid bounds checking in the following operations in release builds. Instead, attempting to write past the marked position in release builds will write to random memory and cause undefined behavior, likely including instability and crashes. |
WriteByte(byte) | Write a byte to the stream. |
WriteByteSafe(byte) | Write a byte to the stream. "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteBytes(byte*, int, int) | Write multiple bytes to the stream |
WriteBytes(byte[], int, int) | Write multiple bytes to the stream |
WriteBytes(NativeArray<byte>, int, int) | Write multiple bytes to the stream |
WriteBytes(NativeList<byte>, int, int) | Write multiple bytes to the stream |
WriteBytesSafe(byte*, int, int) | Write multiple bytes to the stream "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteBytesSafe(byte[], int, int) | Write multiple bytes to the stream "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteBytesSafe(NativeArray<byte>, int, int) | Write multiple bytes to the stream |
WriteBytesSafe(NativeList<byte>, int, int) | Write multiple bytes to the stream |
WriteNetworkSerializable<T>(NativeArray<T>, int, int) | Write a NativeArray of INetworkSerializables |
WriteNetworkSerializable<T>(in T) | Write an INetworkSerializable |
WriteNetworkSerializable<T>(T[], int, int) | Write an array of INetworkSerializables |
WritePartialValue<T>(T, int, int) | Write a partial value. The specified number of bytes is written from the value and the rest is ignored. |
WriteValue(string, bool) | Writes a string |
WriteValue(in Color32) | Write a Color32 |
WriteValue(Color32[]) | Write a Color32 array |
WriteValue(in Color) | Write a Color |
WriteValue(Color[]) | Write a Color array |
WriteValue(in Quaternion) | Write a Quaternion |
WriteValue(Quaternion[]) | Write a Quaternion array |
WriteValue(in Ray2D) | Write a Ray2D |
WriteValue(Ray2D[]) | Write a Ray2D array |
WriteValue(in Ray) | Write a Ray |
WriteValue(Ray[]) | Write a Ray array |
WriteValue(in Vector2) | Write a Vector2 |
WriteValue(in Vector2Int) | Write a Vector2Int |
WriteValue(Vector2Int[]) | Write a Vector2Int array |
WriteValue(Vector2[]) | Write a Vector2 array |
WriteValue(in Vector3) | Write a Vector3 |
WriteValue(in Vector3Int) | Write a Vector3Int |
WriteValue(Vector3Int[]) | Write a Vector3Int array |
WriteValue(Vector3[]) | Write a Vector3 array |
WriteValue(in Vector4) | Write a Vector4 |
WriteValue(Vector4[]) | Write a Vector4 |
WriteValueSafe(string, bool) | Writes a string "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(in Color32) | Write a Color32 "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(Color32[]) | Write a Color32 array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(in Color) | Write a Color "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(Color[]) | Write a Collor array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(in Quaternion) | Write a Quaternion "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(Quaternion[]) | Write a Quaternion array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(in Ray2D) | Write a Ray2D "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(Ray2D[]) | Write a Ray2D array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(in Ray) | Write a Ray "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(Ray[]) | Write a Ray array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(in Vector2) | Write a Vector2 "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(in Vector2Int) | Write a Vector2Int "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(Vector2Int[]) | Write a Vector2Int array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(Vector2[]) | Write a Vector2 array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(in Vector3) | Write a Vector3 "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(in Vector3Int) | Write a Vector3Int "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(Vector3Int[]) | Write a Vector3Int array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(Vector3[]) | Write a Vector3 array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(in Vector4) | Write a Vector4 "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe(Vector4[]) | Write a Vector4 array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe<T>(NativeArray<T>, ForGeneric) | Write a struct NativeArray "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe<T>(in NativeArray<T>) | Write a NativeArray of FixedString values. Writes only the part of each string that's actually used. "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe<T>(in T, ForEnums) | Write an enum value "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe<T>(in T, ForFixedStrings) | Write a FixedString value. Writes only the part of the string that's actually used. "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe<T>(in T, ForNetworkSerializable) | Write a NetworkSerializable value "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe<T>(in T, ForPrimitives) | Write a primitive value (int, bool, etc) Accepts any value that implements the given interfaces, but is not guaranteed to work correctly on values that are not primitives. "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe<T>(in T, ForStructs) | Write a struct "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe<T>(T[], ForEnums) | Write an enum array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe<T>(T[], ForFixedStrings) | Write a NativeArray of FixedString values. Writes only the part of each string that's actually used. "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe<T>(T[], ForNetworkSerializable) | Write a NetworkSerializable array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe<T>(T[], ForPrimitives) | Write a primitive value (int, bool, etc) Accepts any value that implements the given interfaces, but is not guaranteed to work correctly on values that are not primitives. "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValueSafe<T>(T[], ForStructs) | Write a struct array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple writes at once by calling TryBeginWrite. |
WriteValue<T>(NativeArray<T>, ForGeneric) | Write a struct NativeArray |
WriteValue<T>(in NativeArray<T>, ForFixedStrings) | Write a NativeArray of FixedString values. Writes only the part of each string that's actually used. When calling TryBeginWrite, ensure you calculate the write size correctly (preferably by calling FastBufferWriter.GetWriteSize()) |
WriteValue<T>(in T, ForEnums) | Write an enum value |
WriteValue<T>(in T, ForFixedStrings) | Write a FixedString value. Writes only the part of the string that's actually used. When calling TryBeginWrite, ensure you calculate the write size correctly (preferably by calling FastBufferWriter.GetWriteSize()) |
WriteValue<T>(in T, ForNetworkSerializable) | Write a NetworkSerializable value |
WriteValue<T>(in T, ForPrimitives) | Write a primitive value (int, bool, etc) Accepts any value that implements the given interfaces, but is not guaranteed to work correctly on values that are not primitives. |
WriteValue<T>(in T, ForStructs) | Write a struct |
WriteValue<T>(T[], ForEnums) | Write an enum array |
WriteValue<T>(T[], ForFixedStrings) | Write an array of FixedString values. Writes only the part of each string that's actually used. When calling TryBeginWrite, ensure you calculate the write size correctly (preferably by calling FastBufferWriter.GetWriteSize()) |
WriteValue<T>(T[], ForNetworkSerializable) | Write a NetworkSerializable array |
WriteValue<T>(T[], ForPrimitives) | Write a primitive value array (int, bool, etc) Accepts any value that implements the given interfaces, but is not guaranteed to work correctly on values that are not primitives. |
WriteValue<T>(T[], ForStructs) | Write a struct array |