Struct FastBufferReader
Optimized class used for reading values from a byte stream FastBufferWriter BytePacker ByteUnpacker
Inherited Members
Namespace: Unity.Netcode
Syntax
public struct FastBufferReader : IDisposable
Constructors
FastBufferReader(ArraySegment<Byte>, Allocator, Int32, Int32)
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 |
Int32 | length | The number of bytes to copy (all if this is -1) |
Int32 | offset | The offset of the buffer to start copying from |
FastBufferReader(Byte*, Allocator, Int32, Int32, 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 |
Int32 | length | The number of bytes to copy |
Int32 | 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, Int32, Int32)
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 |
Int32 | length | The number of bytes to copy (all if this is -1) |
Int32 | offset | The offset of the buffer to start copying from |
FastBufferReader(NativeArray<Byte>, Allocator, Int32, Int32, 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 |
Int32 | length | |
Int32 | 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, Int32, Int32, 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 |
Int32 | length | The number of bytes to copy (all if this is -1) |
Int32 | 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, Int32, Int32, 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 |
Int32 | length | The number of bytes to copy (all if this is -1) |
Int32 | 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 readonly bool IsInitialized { get; }
Property Value
Type | Description |
---|---|
Boolean |
Length
Get the total length of the buffer
Declaration
public readonly int Length { get; }
Property Value
Type | Description |
---|---|
Int32 |
Position
Get the current read position
Declaration
public readonly int Position { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
Dispose()
IDisposable implementation that frees the allocated buffer
Declaration
public void Dispose()
Implements
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 |
ReadBytes(Byte*, Int32, Int32)
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 |
Int32 | size | Number of bytes to read - MUST BE <= BUFFER SIZE |
Int32 | offset | Offset of the byte buffer to store into |
ReadBytes(ref Byte[], Int32, Int32)
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 |
Int32 | size | Number of bytes to read - MUST BE <= BUFFER SIZE |
Int32 | offset | Offset of the byte buffer to store into |
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 |
ReadBytesSafe(Byte*, Int32, Int32)
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 |
Int32 | size | Number of bytes to read - MUST BE <= BUFFER SIZE |
Int32 | offset | Offset of the byte buffer to store into |
ReadBytesSafe(ref Byte[], Int32, Int32)
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 |
Int32 | size | Number of bytes to read - MUST BE <= BUFFER SIZE |
Int32 | offset | Offset of the byte buffer to store into |
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 |
ReadNetworkSerializable<T>(out NativeArray<T>, Allocator)
Read a NativeArray of INetworkSerializables
Declaration
public void ReadNetworkSerializable<T>(out NativeArray<T> value, Allocator allocator)
where T : struct, 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 |
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 |
ReadPartialValue<T>(out T, Int32, Int32)
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 : struct
Parameters
Type | Name | Description |
---|---|---|
T | value | Value to read |
Int32 | bytesToRead | Number of bytes |
Int32 | 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, Boolean)
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 |
Boolean | oneByteChars | Whether or not to use one byte per character. This will only allow ASCII |
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 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 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 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 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 Vector2)
Read a Vector2
Declaration
public void ReadValue(out Vector2 value)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | the value 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 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 Vector3)
Read a Vector3
Declaration
public void ReadValue(out Vector3 value)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | 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 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 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 |
ReadValue<T>(out T, FastBufferWriter.ForEnums)
Read an enum value
Declaration
public void ReadValue<T>(out T value, FastBufferWriter.ForEnums unused = default(FastBufferWriter.ForEnums))
where T : struct, 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, FastBufferWriter.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(FastBufferWriter.ForFixedStrings))
where T : struct, 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, FastBufferWriter.ForNetworkSerializable)
Read a NetworkSerializable value
Declaration
public void ReadValue<T>(out T value, FastBufferWriter.ForNetworkSerializable unused = default(FastBufferWriter.ForNetworkSerializable))
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, FastBufferWriter.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(FastBufferWriter.ForPrimitives))
where T : struct, 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, FastBufferWriter.ForStructs)
Read a struct
Declaration
public void ReadValue<T>(out T value, FastBufferWriter.ForStructs unused = default(FastBufferWriter.ForStructs))
where T : struct, 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[], FastBufferWriter.ForEnums)
Read an enum array
Declaration
public void ReadValue<T>(out T[] value, FastBufferWriter.ForEnums unused = default(FastBufferWriter.ForEnums))
where T : struct, 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[], FastBufferWriter.ForNetworkSerializable)
Read a NetworkSerializable array
Declaration
public void ReadValue<T>(out T[] value, FastBufferWriter.ForNetworkSerializable unused = default(FastBufferWriter.ForNetworkSerializable))
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[], FastBufferWriter.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(FastBufferWriter.ForPrimitives))
where T : struct, 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[], FastBufferWriter.ForStructs)
Read a struct array
Declaration
public void ReadValue<T>(out T[] value, FastBufferWriter.ForStructs unused = default(FastBufferWriter.ForStructs))
where T : struct, 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 |
ReadValue<T>(out NativeArray<T>, Allocator, FastBufferWriter.ForGeneric)
Read a struct NativeArray
Declaration
public void ReadValue<T>(out NativeArray<T> value, Allocator allocator, FastBufferWriter.ForGeneric unused = default(FastBufferWriter.ForGeneric))
where T : struct
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(out String, Boolean)
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 |
Boolean | oneByteChars | Whether or not to use one byte per character. This will only allow ASCII |
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 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 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 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 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 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 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 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 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 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 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 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 |
ReadValueSafe<T>(out T, FastBufferWriter.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(FastBufferWriter.ForEnums))
where T : struct, 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, FastBufferWriter.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(FastBufferWriter.ForFixedStrings))
where T : struct, 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, FastBufferWriter.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(FastBufferWriter.ForNetworkSerializable))
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, FastBufferWriter.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(FastBufferWriter.ForPrimitives))
where T : struct, 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, FastBufferWriter.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(FastBufferWriter.ForStructs))
where T : struct, 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[], FastBufferWriter.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(FastBufferWriter.ForEnums))
where T : struct, 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[], FastBufferWriter.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(FastBufferWriter.ForFixedStrings))
where T : struct, 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[], FastBufferWriter.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(FastBufferWriter.ForNetworkSerializable))
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[], FastBufferWriter.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(FastBufferWriter.ForPrimitives))
where T : struct, 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[], FastBufferWriter.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(FastBufferWriter.ForStructs))
where T : struct, 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 |
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 : struct, 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, FastBufferWriter.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(FastBufferWriter.ForGeneric))
where T : struct
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, FastBufferWriter.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(FastBufferWriter.ForNetworkSerializable))
where T : struct, 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 |
ReadValueSafeInPlace<T>(ref T, FastBufferWriter.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(FastBufferWriter.ForFixedStrings))
where T : struct, 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 : struct, 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>, FastBufferWriter.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(FastBufferWriter.ForGeneric))
where T : struct
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 |
ReadValueTemp<T>(out NativeArray<T>, FastBufferWriter.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(FastBufferWriter.ForGeneric))
where T : struct
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 |
Seek(Int32)
Move the read position in the stream
Declaration
public void Seek(int where)
Parameters
Type | Name | Description |
---|---|---|
Int32 | 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(Int32)
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 |
---|---|---|
Int32 | bytes | Amount of bytes to read |
Returns
Type | Description |
---|---|
Boolean | 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 : struct
Parameters
Type | Name | Description |
---|---|---|
T | value | The value you want to read |
Returns
Type | Description |
---|---|
Boolean | 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 |