Struct FastBufferReader
Optimized class used for reading values from a byte stream FastBufferWriter BytePacker ByteUnpacker
Implements
Inherited Members
Namespace: Unity.Netcode
Assembly: solution.dll
Syntax
public struct FastBufferReader : IDisposable
Constructors
FastBufferReader(ArraySegment<byte>, Allocator, int, int)
Create a FastBufferReader from an ArraySegment.
A new buffer will be created using the given allocator and the value will be copied in. FastBufferReader will then own the data.
Allocator.None is not supported for byte[]. If you need this functionality, use a fixed() block and ensure the FastBufferReader isn't used outside that block.
Declaration
public FastBufferReader(ArraySegment<byte> buffer, Allocator copyAllocator, int length = -1, int offset = 0)
Parameters
Type | Name | Description |
---|---|---|
ArraySegment<byte> | buffer | The buffer to copy from |
Allocator | copyAllocator | The allocator type used for internal data when copying an existing buffer if other than Allocator.None is specified, that memory will be owned by this FastBufferReader instance |
int | length | The number of bytes to copy (all if this is -1) |
int | offset | The offset of the buffer to start copying from |
FastBufferReader(byte*, Allocator, int, int, Allocator)
Create a FastBufferReader from an existing byte buffer.
A new buffer will be created using the given and the value will be copied in. FastBufferReader will then own the data.
The exception to this is when the passed in is Allocator.None. In this scenario, ownership of the data remains with the caller and the reader will point at it directly. When created with Allocator.None, FastBufferReader will allocate some internal data using Allocator.Temp, so it should be treated as if it's a ref struct and not allowed to outlive the context in which it was created (it should neither be returned from that function nor stored anywhere in heap memory). This is true, unless the param is explicitly set to i.e.: Allocator.Persistent in which case it would allow the internal data to Persist for longer, but the caller should manually call Dispose() when it is no longer needed.
Declaration
public FastBufferReader(byte* buffer, Allocator copyAllocator, int length, int offset = 0, Allocator internalAllocator = Allocator.Temp)
Parameters
Type | Name | Description |
---|---|---|
byte* | buffer | The buffer to copy from |
Allocator | copyAllocator | The allocator type used for internal data when copying an existing buffer if other than Allocator.None is specified, that memory will be owned by this FastBufferReader instance |
int | length | The number of bytes to copy |
int | offset | The offset of the buffer to start copying from |
Allocator | internalAllocator | The allocator type used for internal data when this reader points directly at a buffer owned by someone else |
FastBufferReader(byte[], Allocator, int, int)
Create a FastBufferReader from an existing byte array.
A new buffer will be created using the given allocator and the value will be copied in. FastBufferReader will then own the data.
Allocator.None is not supported for byte[]. If you need this functionality, use a fixed() block and ensure the FastBufferReader isn't used outside that block.
Declaration
public FastBufferReader(byte[] buffer, Allocator copyAllocator, int length = -1, int offset = 0)
Parameters
Type | Name | Description |
---|---|---|
byte[] | buffer | The buffer to copy from |
Allocator | copyAllocator | The allocator type used for internal data when copying an existing buffer if other than Allocator.None is specified, that memory will be owned by this FastBufferReader instance |
int | length | The number of bytes to copy (all if this is -1) |
int | offset | The offset of the buffer to start copying from |
FastBufferReader(NativeArray<byte>, Allocator, int, int, Allocator)
Create a FastBufferReader from a NativeArray.
A new buffer will be created using the given and the value will be copied in. FastBufferReader will then own the data.
The exception to this is when the passed in is Allocator.None. In this scenario, ownership of the data remains with the caller and the reader will point at it directly. When created with Allocator.None, FastBufferReader will allocate some internal data using Allocator.Temp so it should be treated as if it's a ref struct and not allowed to outlive the context in which it was created (it should neither be returned from that function nor stored anywhere in heap memory). This is true, unless the param is explicitly set to i.e.: Allocator.Persistent in which case it would allow the internal data to Persist for longer, but the caller should manually call Dispose() when it is no longer needed.
Declaration
public FastBufferReader(NativeArray<byte> buffer, Allocator copyAllocator, int length = -1, int offset = 0, Allocator internalAllocator = Allocator.Temp)
Parameters
Type | Name | Description |
---|---|---|
NativeArray<byte> | buffer | |
Allocator | copyAllocator | The allocator type used for internal data when copying an existing buffer if other than Allocator.None is specified, that memory will be owned by this FastBufferReader instance |
int | length | |
int | offset | |
Allocator | internalAllocator | The allocator type used for internal data when this reader points directly at a buffer owned by someone else |
FastBufferReader(FastBufferReader, Allocator, int, int, Allocator)
Create a FastBufferReader from another existing FastBufferReader. This is typically used when you want to change the copyAllocator that a reader is allocated to - for example, upgrading a Temp reader to a Persistent one to be processed later.
A new buffer will be created using the given and the value will be copied in. FastBufferReader will then own the data.
The exception to this is when the passed in is Allocator.None. In this scenario, ownership of the data remains with the caller and the reader will point at it directly. When created with Allocator.None, FastBufferReader will allocate some internal data using Allocator.Temp, so it should be treated as if it's a ref struct and not allowed to outlive the context in which it was created (it should neither be returned from that function nor stored anywhere in heap memory).
Declaration
public FastBufferReader(FastBufferReader reader, Allocator copyAllocator, int length = -1, int offset = 0, Allocator internalAllocator = Allocator.Temp)
Parameters
Type | Name | Description |
---|---|---|
FastBufferReader | reader | The reader to copy from |
Allocator | copyAllocator | The allocator type used for internal data when copying an existing buffer if other than Allocator.None is specified, that memory will be owned by this FastBufferReader instance |
int | length | The number of bytes to copy (all if this is -1) |
int | offset | The offset of the buffer to start copying from |
Allocator | internalAllocator | The allocator type used for internal data when this reader points directly at a buffer owned by someone else |
FastBufferReader(FastBufferWriter, Allocator, int, int, Allocator)
Create a FastBufferReader from a FastBufferWriter.
A new buffer will be created using the given and the value will be copied in. FastBufferReader will then own the data.
The exception to this is when the passed in is Allocator.None. In this scenario, ownership of the data remains with the caller and the reader will point at it directly. When created with Allocator.None, FastBufferReader will allocate some internal data using Allocator.Temp, so it should be treated as if it's a ref struct and not allowed to outlive the context in which it was created (it should neither be returned from that function nor stored anywhere in heap memory). This is true, unless the param is explicitly set to i.e.: Allocator.Persistent in which case it would allow the internal data to Persist for longer, but the caller should manually call Dispose() when it is no longer needed.
Declaration
public FastBufferReader(FastBufferWriter writer, Allocator copyAllocator, int length = -1, int offset = 0, Allocator internalAllocator = Allocator.Temp)
Parameters
Type | Name | Description |
---|---|---|
FastBufferWriter | writer | The writer to copy from |
Allocator | copyAllocator | The allocator type used for internal data when copying an existing buffer if other than Allocator.None is specified, that memory will be owned by this FastBufferReader instance |
int | length | The number of bytes to copy (all if this is -1) |
int | offset | The offset of the buffer to start copying from |
Allocator | internalAllocator | The allocator type used for internal data when this reader points directly at a buffer owned by someone else |
Properties
IsInitialized
Gets a value indicating whether the reader has been initialized and a handle allocated.
Declaration
public bool IsInitialized { get; }
Property Value
Type | Description |
---|---|
bool |
Length
Get the total length of the buffer
Declaration
public int Length { get; }
Property Value
Type | Description |
---|---|
int |
Position
Get the current read position
Declaration
public int Position { get; }
Property Value
Type | Description |
---|---|
int |
Methods
Dispose()
IDisposable implementation that frees the allocated buffer
Declaration
public void Dispose()
EnterBitwiseContext()
Retrieve a BitReader to be able to perform bitwise operations on the buffer. No bytewise operations can be performed on the buffer until bitReader.Dispose() has been called. At the end of the operation, FastBufferReader will remain byte-aligned.
Declaration
public BitReader EnterBitwiseContext()
Returns
Type | Description |
---|---|
BitReader | A BitReader |
GetUnsafePtr()
Gets a direct pointer to the underlying buffer
Declaration
public byte* GetUnsafePtr()
Returns
Type | Description |
---|---|
byte* | byte pointer |
GetUnsafePtrAtCurrentPosition()
Gets a direct pointer to the underlying buffer at the current read position
Declaration
public byte* GetUnsafePtrAtCurrentPosition()
Returns
Type | Description |
---|---|
byte* | byte pointer |
ReadByte(out byte)
Read a byte to the stream.
Declaration
public void ReadByte(out byte value)
Parameters
Type | Name | Description |
---|---|---|
byte | value | Stores the read value |
ReadByteSafe(out byte)
Read a byte to the stream.
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadByteSafe(out byte value)
Parameters
Type | Name | Description |
---|---|---|
byte | value | Stores the read value |
ReadBytes(byte*, int, int)
Read multiple bytes to the stream
Declaration
public void ReadBytes(byte* value, int size, int offset = 0)
Parameters
Type | Name | Description |
---|---|---|
byte* | value | Pointer to the destination buffer |
int | size | Number of bytes to read - MUST BE <= BUFFER SIZE |
int | offset | Offset of the byte buffer to store into |
ReadBytes(ref byte[], int, int)
Read multiple bytes from the stream
Declaration
public void ReadBytes(ref byte[] value, int size, int offset = 0)
Parameters
Type | Name | Description |
---|---|---|
byte[] | value | Pointer to the destination buffer |
int | size | Number of bytes to read - MUST BE <= BUFFER SIZE |
int | offset | Offset of the byte buffer to store into |
ReadBytesSafe(byte*, int, int)
Read multiple bytes to the stream
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadBytesSafe(byte* value, int size, int offset = 0)
Parameters
Type | Name | Description |
---|---|---|
byte* | value | Pointer to the destination buffer |
int | size | Number of bytes to read - MUST BE <= BUFFER SIZE |
int | offset | Offset of the byte buffer to store into |
ReadBytesSafe(ref byte[], int, int)
Read multiple bytes from the stream
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadBytesSafe(ref byte[] value, int size, int offset = 0)
Parameters
Type | Name | Description |
---|---|---|
byte[] | value | Pointer to the destination buffer |
int | size | Number of bytes to read - MUST BE <= BUFFER SIZE |
int | offset | Offset of the byte buffer to store into |
ReadNetworkSerializableInPlace<T>(ref T)
Read an INetworkSerializable in-place, without constructing a new one Note that this will NOT check for null before calling NetworkSerialize
Declaration
public void ReadNetworkSerializableInPlace<T>(ref T value) where T : INetworkSerializable
Parameters
Type | Name | Description |
---|---|---|
T | value | INetworkSerializable instance |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
NotImplementedException |
ReadNetworkSerializable<T>(out NativeArray<T>, Allocator)
Read a NativeArray of INetworkSerializables
Declaration
public void ReadNetworkSerializable<T>(out NativeArray<T> value, Allocator allocator) where T : unmanaged, INetworkSerializable
Parameters
Type | Name | Description |
---|---|---|
NativeArray<T> | value | INetworkSerializable instance |
Allocator | allocator | The allocator to use to construct the resulting NativeArray |
Type Parameters
Name | Description |
---|---|
T | the array to read the values of type |
Exceptions
Type | Condition |
---|---|
NotImplementedException |
ReadNetworkSerializable<T>(out T)
Read an INetworkSerializable
Declaration
public void ReadNetworkSerializable<T>(out T value) where T : INetworkSerializable, new()
Parameters
Type | Name | Description |
---|---|---|
T | value | INetworkSerializable instance |
Type Parameters
Name | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
NotImplementedException |
ReadNetworkSerializable<T>(out T[])
Read an array of INetworkSerializables
Declaration
public void ReadNetworkSerializable<T>(out T[] value) where T : INetworkSerializable, new()
Parameters
Type | Name | Description |
---|---|---|
T[] | value | INetworkSerializable instance |
Type Parameters
Name | Description |
---|---|
T | the array to read the values of type |
Exceptions
Type | Condition |
---|---|
NotImplementedException |
ReadPartialValue<T>(out T, int, int)
Read a partial value. The value is zero-initialized and then the specified number of bytes is read into it.
Declaration
public void ReadPartialValue<T>(out T value, int bytesToRead, int offsetBytes = 0) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
T | value | Value to read |
int | bytesToRead | Number of bytes |
int | offsetBytes | Offset into the value to write the bytes |
Type Parameters
Name | Description |
---|---|
T | the type value to read the value into |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | |
OverflowException |
ReadValue(out string, bool)
Reads a string NOTE: ALLOCATES
Declaration
public void ReadValue(out string s, bool oneByteChars = false)
Parameters
Type | Name | Description |
---|---|---|
string | s | Stores the read string |
bool | oneByteChars | Whether or not to use one byte per character. This will only allow ASCII |
ReadValue(out Color32)
Read a Color32
Declaration
public void ReadValue(out Color32 value)
Parameters
Type | Name | Description |
---|---|---|
Color32 | value | the value to read |
ReadValue(out Color32[])
Read a Color32 array
Declaration
public void ReadValue(out Color32[] value)
Parameters
Type | Name | Description |
---|---|---|
Color32[] | value | the values to read |
ReadValue(out Color)
Read a Color
Declaration
public void ReadValue(out Color value)
Parameters
Type | Name | Description |
---|---|---|
Color | value | the value to read |
ReadValue(out Color[])
Read a Color array
Declaration
public void ReadValue(out Color[] value)
Parameters
Type | Name | Description |
---|---|---|
Color[] | value | the values to read |
ReadValue(out Quaternion)
Read a Quaternion
Declaration
public void ReadValue(out Quaternion value)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value | the value to read |
ReadValue(out Quaternion[])
Read a Quaternion array
Declaration
public void ReadValue(out Quaternion[] value)
Parameters
Type | Name | Description |
---|---|---|
Quaternion[] | value | the values to read |
ReadValue(out Ray2D)
Read a Ray2D
Declaration
public void ReadValue(out Ray2D value)
Parameters
Type | Name | Description |
---|---|---|
Ray2D | value | the value to read |
ReadValue(out Ray2D[])
Read a Ray2D array
Declaration
public void ReadValue(out Ray2D[] value)
Parameters
Type | Name | Description |
---|---|---|
Ray2D[] | value | the values to read |
ReadValue(out Ray)
Read a Ray
Declaration
public void ReadValue(out Ray value)
Parameters
Type | Name | Description |
---|---|---|
Ray | value | the value to read |
ReadValue(out Ray[])
Read a Ray array
Declaration
public void ReadValue(out Ray[] value)
Parameters
Type | Name | Description |
---|---|---|
Ray[] | value | the values to read |
ReadValue(out Vector2)
Read a Vector2
Declaration
public void ReadValue(out Vector2 value)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | the value to read |
ReadValue(out Vector2Int)
Read a Vector2Int
Declaration
public void ReadValue(out Vector2Int value)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | value | the value to read |
ReadValue(out Vector2Int[])
Read a Vector2Int array
Declaration
public void ReadValue(out Vector2Int[] value)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int[] | value | the values to read |
ReadValue(out Vector2[])
Read a Vector2 array
Declaration
public void ReadValue(out Vector2[] value)
Parameters
Type | Name | Description |
---|---|---|
Vector2[] | value | the values to read |
ReadValue(out Vector3)
Read a Vector3
Declaration
public void ReadValue(out Vector3 value)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | value | the value to read |
ReadValue(out Vector3Int)
Read a Vector3Int
Declaration
public void ReadValue(out Vector3Int value)
Parameters
Type | Name | Description |
---|---|---|
Vector3Int | value | the value to read |
ReadValue(out Vector3Int[])
Read a Vector3Int array
Declaration
public void ReadValue(out Vector3Int[] value)
Parameters
Type | Name | Description |
---|---|---|
Vector3Int[] | value | the value to read |
ReadValue(out Vector3[])
Read a Vector3 array
Declaration
public void ReadValue(out Vector3[] value)
Parameters
Type | Name | Description |
---|---|---|
Vector3[] | value | the values to read |
ReadValue(out Vector4)
Read a Vector4
Declaration
public void ReadValue(out Vector4 value)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | value | the value to read |
ReadValue(out Vector4[])
Read a Vector4
Declaration
public void ReadValue(out Vector4[] value)
Parameters
Type | Name | Description |
---|---|---|
Vector4[] | value | the values to read |
ReadValueSafe(out string, bool)
Reads a string. NOTE: ALLOCATES
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out string s, bool oneByteChars = false)
Parameters
Type | Name | Description |
---|---|---|
string | s | Stores the read string |
bool | oneByteChars | Whether or not to use one byte per character. This will only allow ASCII |
ReadValueSafe(out Color32)
Read a Color32
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Color32 value)
Parameters
Type | Name | Description |
---|---|---|
Color32 | value | the value to read |
ReadValueSafe(out Color32[])
Read a Color32 array
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Color32[] value)
Parameters
Type | Name | Description |
---|---|---|
Color32[] | value | the values to read |
ReadValueSafe(out Color)
Read a Color
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Color value)
Parameters
Type | Name | Description |
---|---|---|
Color | value | the value to read |
ReadValueSafe(out Color[])
Read a Collor array
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Color[] value)
Parameters
Type | Name | Description |
---|---|---|
Color[] | value | the values to read |
ReadValueSafe(out Quaternion)
Read a Quaternion
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Quaternion value)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value | the value to read |
ReadValueSafe(out Quaternion[])
Read a Quaternion array
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Quaternion[] value)
Parameters
Type | Name | Description |
---|---|---|
Quaternion[] | value | the values to read |
ReadValueSafe(out Ray2D)
Read a Ray2D
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Ray2D value)
Parameters
Type | Name | Description |
---|---|---|
Ray2D | value | the value to read |
ReadValueSafe(out Ray2D[])
Read a Ray2D array
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Ray2D[] value)
Parameters
Type | Name | Description |
---|---|---|
Ray2D[] | value | the values to read |
ReadValueSafe(out Ray)
Read a Ray
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Ray value)
Parameters
Type | Name | Description |
---|---|---|
Ray | value | the value to read |
ReadValueSafe(out Ray[])
Read a Ray array
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Ray[] value)
Parameters
Type | Name | Description |
---|---|---|
Ray[] | value | the values to read |
ReadValueSafe(out Vector2)
Read a Vector2
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Vector2 value)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | the value to read |
ReadValueSafe(out Vector2Int)
Read a Vector2Int
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Vector2Int value)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | value | the value to read |
ReadValueSafe(out Vector2Int[])
Read a Vector2Int array
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Vector2Int[] value)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int[] | value | the values to read |
ReadValueSafe(out Vector2[])
Read a Vector2 array
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Vector2[] value)
Parameters
Type | Name | Description |
---|---|---|
Vector2[] | value | the values to read |
ReadValueSafe(out Vector3)
Read a Vector3
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Vector3 value)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | value | the value to read |
ReadValueSafe(out Vector3Int)
Read a Vector3Int
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Vector3Int value)
Parameters
Type | Name | Description |
---|---|---|
Vector3Int | value | the value to read |
ReadValueSafe(out Vector3Int[])
Read a Vector3Int array
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Vector3Int[] value)
Parameters
Type | Name | Description |
---|---|---|
Vector3Int[] | value | the values to read |
ReadValueSafe(out Vector3[])
Read a Vector3 array
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Vector3[] value)
Parameters
Type | Name | Description |
---|---|---|
Vector3[] | value | the values to read |
ReadValueSafe(out Vector4)
Read a Vector4
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Vector4 value)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | value | the value to read |
ReadValueSafe(out Vector4[])
Read a Vector4 array
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe(out Vector4[] value)
Parameters
Type | Name | Description |
---|---|---|
Vector4[] | value | the values to read |
ReadValueSafeInPlace<T>(ref T, ForFixedStrings)
Read a FixedString value.
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafeInPlace<T>(ref T value, FastBufferWriter.ForFixedStrings unused = default) where T : unmanaged, INativeList<byte>, IUTF8Bytes
Parameters
Type | Name | Description |
---|---|---|
T | value | the value to read |
FastBufferWriter.ForFixedStrings | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValueSafeTemp<T>(out NativeArray<T>)
Read a FixedString NativeArray using a Temp allocator. Equivalent to ReadValueSafe(out value, Allocator.Temp)
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafeTemp<T>(out NativeArray<T> value) where T : unmanaged, INativeList<byte>, IUTF8Bytes
Parameters
Type | Name | Description |
---|---|---|
NativeArray<T> | value | the value to read |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValueSafeTemp<T>(out NativeArray<T>, ForGeneric)
Read a struct NativeArray using a Temp allocator. Equivalent to ReadValueSafe(out value, Allocator.Temp)
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafeTemp<T>(out NativeArray<T> value, FastBufferWriter.ForGeneric unused = default) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
NativeArray<T> | value | The values to read |
FastBufferWriter.ForGeneric | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValueSafe<T>(out NativeArray<T>, Allocator)
Read a FixedString NativeArray.
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe<T>(out NativeArray<T> value, Allocator allocator) where T : unmanaged, INativeList<byte>, IUTF8Bytes
Parameters
Type | Name | Description |
---|---|---|
NativeArray<T> | value | the value to read |
Allocator | allocator | The allocator to use to construct the resulting NativeArray |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValueSafe<T>(out NativeArray<T>, Allocator, ForGeneric)
Read a struct NativeArray
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe<T>(out NativeArray<T> value, Allocator allocator, FastBufferWriter.ForGeneric unused = default) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
NativeArray<T> | value | The values to read |
Allocator | allocator | The allocator to use to construct the resulting NativeArray |
FastBufferWriter.ForGeneric | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValueSafe<T>(out NativeArray<T>, Allocator, ForNetworkSerializable)
Read a NetworkSerializable NativeArray
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe<T>(out NativeArray<T> value, Allocator allocator, FastBufferWriter.ForNetworkSerializable unused = default) where T : unmanaged, INetworkSerializable
Parameters
Type | Name | Description |
---|---|---|
NativeArray<T> | value | The values to read |
Allocator | allocator | The allocator to use to construct the resulting NativeArray |
FastBufferWriter.ForNetworkSerializable | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValueSafe<T>(out T, ForEnums)
Read an enum value
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe<T>(out T value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to read |
FastBufferWriter.ForEnums | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValueSafe<T>(out T, ForFixedStrings)
Read a FixedString value.
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe<T>(out T value, FastBufferWriter.ForFixedStrings unused = default) where T : unmanaged, INativeList<byte>, IUTF8Bytes
Parameters
Type | Name | Description |
---|---|---|
T | value | the value to read |
FastBufferWriter.ForFixedStrings | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValueSafe<T>(out T, ForNetworkSerializable)
Read a NetworkSerializable value
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe<T>(out T value, FastBufferWriter.ForNetworkSerializable unused = default) where T : INetworkSerializable, new()
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to read |
FastBufferWriter.ForNetworkSerializable | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValueSafe<T>(out T, ForPrimitives)
Read 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 reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe<T>(out T value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable<T>, IEquatable<T>
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to read |
FastBufferWriter.ForPrimitives | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValueSafe<T>(out T, ForStructs)
Read a struct
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe<T>(out T value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to read |
FastBufferWriter.ForStructs | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValueSafe<T>(out T[], ForEnums)
Read an enum array
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe<T>(out T[] value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum
Parameters
Type | Name | Description |
---|---|---|
T[] | value | The values to read |
FastBufferWriter.ForEnums | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValueSafe<T>(out T[], ForFixedStrings)
Read a FixedString NativeArray using a Temp allocator. Equivalent to ReadValueSafe(out value, Allocator.Temp)
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe<T>(out T[] value, FastBufferWriter.ForFixedStrings unused = default) where T : unmanaged, INativeList<byte>, IUTF8Bytes
Parameters
Type | Name | Description |
---|---|---|
T[] | value | the value to read |
FastBufferWriter.ForFixedStrings | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValueSafe<T>(out T[], ForNetworkSerializable)
Read a NetworkSerializable array
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe<T>(out T[] value, FastBufferWriter.ForNetworkSerializable unused = default) where T : INetworkSerializable, new()
Parameters
Type | Name | Description |
---|---|---|
T[] | value | The values to read |
FastBufferWriter.ForNetworkSerializable | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValueSafe<T>(out T[], ForPrimitives)
Read a primitive value (int, bool, etc) array 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 reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe<T>(out T[] value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable<T>, IEquatable<T>
Parameters
Type | Name | Description |
---|---|---|
T[] | value | The value to read |
FastBufferWriter.ForPrimitives | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValueSafe<T>(out T[], ForStructs)
Read a struct array
"Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead.
Declaration
public void ReadValueSafe<T>(out T[] value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy
Parameters
Type | Name | Description |
---|---|---|
T[] | value | The values to read |
FastBufferWriter.ForStructs | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValueTemp<T>(out NativeArray<T>, ForGeneric)
Read a struct NativeArray using a Temp allocator. Equivalent to ReadValue(out value, Allocator.Temp)
Declaration
public void ReadValueTemp<T>(out NativeArray<T> value, FastBufferWriter.ForGeneric unused = default) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
NativeArray<T> | value | The values to read |
FastBufferWriter.ForGeneric | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValue<T>(out NativeArray<T>, Allocator, ForGeneric)
Read a struct NativeArray
Declaration
public void ReadValue<T>(out NativeArray<T> value, Allocator allocator, FastBufferWriter.ForGeneric unused = default) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
NativeArray<T> | value | The values to read |
Allocator | allocator | The allocator to use to construct the resulting NativeArray |
FastBufferWriter.ForGeneric | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValue<T>(out T, ForEnums)
Read an enum value
Declaration
public void ReadValue<T>(out T value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to read |
FastBufferWriter.ForEnums | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValue<T>(out T, ForFixedStrings)
Read a FixedString value. This method is a little difficult to use, since you have to know the size of the string before reading it, but is useful when the string is a known, fixed size. Note that the size of the string is also encoded, so the size to call TryBeginRead on is actually the fixed size (in bytes) plus sizeof(int)
Declaration
public void ReadValue<T>(out T value, FastBufferWriter.ForFixedStrings unused = default) where T : unmanaged, INativeList<byte>, IUTF8Bytes
Parameters
Type | Name | Description |
---|---|---|
T | value | the value to read |
FastBufferWriter.ForFixedStrings | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValue<T>(out T, ForNetworkSerializable)
Read a NetworkSerializable value
Declaration
public void ReadValue<T>(out T value, FastBufferWriter.ForNetworkSerializable unused = default) where T : INetworkSerializable, new()
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to read |
FastBufferWriter.ForNetworkSerializable | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValue<T>(out T, ForPrimitives)
Read 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.
Declaration
public void ReadValue<T>(out T value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable<T>, IEquatable<T>
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to read |
FastBufferWriter.ForPrimitives | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValue<T>(out T, ForStructs)
Read a struct
Declaration
public void ReadValue<T>(out T value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy
Parameters
Type | Name | Description |
---|---|---|
T | value | The value to read |
FastBufferWriter.ForStructs | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValue<T>(out T[], ForEnums)
Read an enum array
Declaration
public void ReadValue<T>(out T[] value, FastBufferWriter.ForEnums unused = default) where T : unmanaged, Enum
Parameters
Type | Name | Description |
---|---|---|
T[] | value | The values to read |
FastBufferWriter.ForEnums | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValue<T>(out T[], ForNetworkSerializable)
Read a NetworkSerializable array
Declaration
public void ReadValue<T>(out T[] value, FastBufferWriter.ForNetworkSerializable unused = default) where T : INetworkSerializable, new()
Parameters
Type | Name | Description |
---|---|---|
T[] | value | The values to read |
FastBufferWriter.ForNetworkSerializable | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValue<T>(out T[], ForPrimitives)
Read 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.
Declaration
public void ReadValue<T>(out T[] value, FastBufferWriter.ForPrimitives unused = default) where T : unmanaged, IComparable, IConvertible, IComparable<T>, IEquatable<T>
Parameters
Type | Name | Description |
---|---|---|
T[] | value | The values to read |
FastBufferWriter.ForPrimitives | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
ReadValue<T>(out T[], ForStructs)
Read a struct array
Declaration
public void ReadValue<T>(out T[] value, FastBufferWriter.ForStructs unused = default) where T : unmanaged, INetworkSerializeByMemcpy
Parameters
Type | Name | Description |
---|---|---|
T[] | value | The values to read |
FastBufferWriter.ForStructs | unused | An unused parameter used for enabling overload resolution based on generic constraints |
Type Parameters
Name | Description |
---|---|
T | The type being serialized |
Seek(int)
Move the read position in the stream
Declaration
public void Seek(int where)
Parameters
Type | Name | Description |
---|---|---|
int | where | Absolute value to move the position to, truncated to Length |
ToArray()
Returns an array representation of the underlying byte buffer. !!Allocates a new array!!
Declaration
public byte[] ToArray()
Returns
Type | Description |
---|---|
byte[] | byte array |
TryBeginRead(int)
Allows faster serialization by batching bounds checking. When you know you will be reading multiple fields back-to-back and you know the total size, you can call TryBeginRead() once on the total size, and then follow it with calls to ReadValue() instead of ReadValueSafe() for faster serialization.
Unsafe read operations will throw OverflowException in editor and development builds if you go past the point you've marked using TryBeginRead(). In release builds, OverflowException will not be thrown for performance reasons, since the point of using TryBeginRead is to avoid bounds checking in the following operations in release builds.
Declaration
public bool TryBeginRead(int bytes)
Parameters
Type | Name | Description |
---|---|---|
int | bytes | Amount of bytes to read |
Returns
Type | Description |
---|---|
bool | True if the read is allowed, false otherwise |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | If called while in a bitwise context |
TryBeginReadValue<T>(in T)
Allows faster serialization by batching bounds checking. When you know you will be reading multiple fields back-to-back and you know the total size, you can call TryBeginRead() once on the total size, and then follow it with calls to ReadValue() instead of ReadValueSafe() for faster serialization.
Unsafe read operations will throw OverflowException in editor and development builds if you go past the point you've marked using TryBeginRead(). In release builds, OverflowException will not be thrown for performance reasons, since the point of using TryBeginRead is to avoid bounds checking in the following operations in release builds.
Declaration
public bool TryBeginReadValue<T>(in T value) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
T | value | The value you want to read |
Returns
Type | Description |
---|---|
bool | True if the read is allowed, false otherwise |
Type Parameters
Name | Description |
---|---|
T | the type |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | If called while in a bitwise context |