Skip to main content

Struct FastBufferReader

Optimized class used for reading values from a byte stream FastBufferWriter BytePacker ByteUnpacker

Implements

System.IDisposable

Inherited Members

System.ValueType.Equals(System.Object)

System.ValueType.GetHashCode()

System.ValueType.ToString()

System.Object.Equals(System.Object, System.Object)

System.Object.GetType()

System.Object.ReferenceEquals(System.Object, System.Object)

Namespace: Unity.Netcode
Assembly: MLAPI.dll
Syntax
public struct FastBufferReader : IDisposable

Constructors

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 = null)
Parameters
TypeNameDescription
NativeArray\<System.Byte>buffer
AllocatorcopyAllocatorThe 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
System.Int32length
System.Int32offset
AllocatorinternalAllocatorThe allocator type used for internal data when this reader points directly at a buffer owned by someone else

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
TypeNameDescription
System.ArraySegment\<System.Byte>bufferThe buffer to copy from
AllocatorcopyAllocatorThe 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
System.Int32lengthThe number of bytes to copy (all if this is -1)
System.Int32offsetThe 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 = null)
Parameters
TypeNameDescription
System.Byte*bufferThe buffer to copy from
AllocatorcopyAllocatorThe 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
System.Int32lengthThe number of bytes to copy
System.Int32offsetThe offset of the buffer to start copying from
AllocatorinternalAllocatorThe 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
TypeNameDescription
System.Byte[]bufferThe buffer to copy from
AllocatorcopyAllocatorThe 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
System.Int32lengthThe number of bytes to copy (all if this is -1)
System.Int32offsetThe offset of the buffer to start copying from

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 = null)
Parameters
TypeNameDescription
FastBufferReaderreaderThe reader to copy from
AllocatorcopyAllocatorThe 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
System.Int32lengthThe number of bytes to copy (all if this is -1)
System.Int32offsetThe offset of the buffer to start copying from
AllocatorinternalAllocatorThe 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 = null)
Parameters
TypeNameDescription
FastBufferWriterwriterThe writer to copy from
AllocatorcopyAllocatorThe 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
System.Int32lengthThe number of bytes to copy (all if this is -1)
System.Int32offsetThe offset of the buffer to start copying from
AllocatorinternalAllocatorThe 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
TypeDescription
System.Boolean

Length

Get the total length of the buffer

Declaration
public readonly int Length { get; }
Property Value
TypeDescription
System.Int32

Position

Get the current read position

Declaration
public readonly int Position { get; }
Property Value
TypeDescription
System.Int32

Methods

Dispose()

System.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
TypeDescription
BitReaderA BitReader

GetUnsafePtr()

Gets a direct pointer to the underlying buffer

Declaration
public byte *GetUnsafePtr()
Returns
TypeDescription
System.Byte*System.Byte pointer

GetUnsafePtrAtCurrentPosition()

Gets a direct pointer to the underlying buffer at the current read position

Declaration
public byte *GetUnsafePtrAtCurrentPosition()
Returns
TypeDescription
System.Byte*System.Byte pointer

ReadByte(out Byte)

Read a byte to the stream.

Declaration
public void ReadByte(out byte value)
Parameters
TypeNameDescription
System.BytevalueStores 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
TypeNameDescription
System.Byte*valuePointer to the destination buffer
System.Int32sizeNumber of bytes to read - MUST BE \<= BUFFER SIZE
System.Int32offsetOffset 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
TypeNameDescription
System.Byte[]valuePointer to the destination buffer
System.Int32sizeNumber of bytes to read - MUST BE \<= BUFFER SIZE
System.Int32offsetOffset 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
TypeNameDescription
System.BytevalueStores 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
TypeNameDescription
System.Byte*valuePointer to the destination buffer
System.Int32sizeNumber of bytes to read - MUST BE \<= BUFFER SIZE
System.Int32offsetOffset 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
TypeNameDescription
System.Byte[]valuePointer to the destination buffer
System.Int32sizeNumber of bytes to read - MUST BE \<= BUFFER SIZE
System.Int32offsetOffset 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
TypeNameDescription
TvalueINetworkSerializable instance
Type Parameters
NameDescription
T
Exceptions
TypeCondition
System.NotImplementedException

ReadNetworkSerializable\<T>(out T[])

Read an array of INetworkSerializables

Declaration
public void ReadNetworkSerializable<T>(out T[] value)
where T : INetworkSerializable, new()
Parameters
TypeNameDescription
T[]valueINetworkSerializable instance
Type Parameters
NameDescription
Tthe array to read the values of type T into
Exceptions
TypeCondition
System.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
TypeNameDescription
TvalueValue to read
System.Int32bytesToReadNumber of bytes
System.Int32offsetBytesOffset into the value to write the bytes
Type Parameters
NameDescription
Tthe type value to read the value into
Exceptions
TypeCondition
System.InvalidOperationException
System.OverflowException

ReadValue(out Color)

Read a Color

Declaration
public void ReadValue(out Color value)
Parameters
TypeNameDescription
Colorvaluethe value to read

ReadValue(out Color[])

Read a Color array

Declaration
public void ReadValue(out Color[] value)
Parameters
TypeNameDescription
Color[]valuethe values to read

ReadValue(out Color32)

Read a Color32

Declaration
public void ReadValue(out Color32 value)
Parameters
TypeNameDescription
Color32valuethe value to read

ReadValue(out Color32[])

Read a Color32 array

Declaration
public void ReadValue(out Color32[] value)
Parameters
TypeNameDescription
Color32[]valuethe values to read

ReadValue(out Quaternion)

Read a Quaternion

Declaration
public void ReadValue(out Quaternion value)
Parameters
TypeNameDescription
Quaternionvaluethe value to read

ReadValue(out Quaternion[])

Read a Quaternion array

Declaration
public void ReadValue(out Quaternion[] value)
Parameters
TypeNameDescription
Quaternion[]valuethe values to read

ReadValue(out Ray)

Read a Ray

Declaration
public void ReadValue(out Ray value)
Parameters
TypeNameDescription
Rayvaluethe value to read

ReadValue(out Ray[])

Read a Ray array

Declaration
public void ReadValue(out Ray[] value)
Parameters
TypeNameDescription
Ray[]valuethe values to read

ReadValue(out Ray2D)

Read a Ray2D

Declaration
public void ReadValue(out Ray2D value)
Parameters
TypeNameDescription
Ray2Dvaluethe value to read

ReadValue(out Ray2D[])

Read a Ray2D array

Declaration
public void ReadValue(out Ray2D[] value)
Parameters
TypeNameDescription
Ray2D[]valuethe values to read

ReadValue(out String, Boolean)

Reads a string NOTE: ALLOCATES

Declaration
public void ReadValue(out string s, bool oneByteChars = false)
Parameters
TypeNameDescription
System.StringsStores the read string
System.BooleanoneByteCharsWhether or not to use one byte per character. This will only allow ASCII

ReadValue(out Vector2)

Read a Vector2

Declaration
public void ReadValue(out Vector2 value)
Parameters
TypeNameDescription
Vector2valuethe value to read

ReadValue(out Vector2[])

Read a Vector2 array

Declaration
public void ReadValue(out Vector2[] value)
Parameters
TypeNameDescription
Vector2[]valuethe values to read

ReadValue(out Vector2Int)

Read a Vector2Int

Declaration
public void ReadValue(out Vector2Int value)
Parameters
TypeNameDescription
Vector2Intvaluethe value to read

ReadValue(out Vector2Int[])

Read a Vector2Int array

Declaration
public void ReadValue(out Vector2Int[] value)
Parameters
TypeNameDescription
Vector2Int[]valuethe values to read

ReadValue(out Vector3)

Read a Vector3

Declaration
public void ReadValue(out Vector3 value)
Parameters
TypeNameDescription
Vector3valuethe value to read

ReadValue(out Vector3[])

Read a Vector3 array

Declaration
public void ReadValue(out Vector3[] value)
Parameters
TypeNameDescription
Vector3[]valuethe values to read

ReadValue(out Vector3Int)

Read a Vector3Int

Declaration
public void ReadValue(out Vector3Int value)
Parameters
TypeNameDescription
Vector3Intvaluethe value to read

ReadValue(out Vector3Int[])

Read a Vector3Int array

Declaration
public void ReadValue(out Vector3Int[] value)
Parameters
TypeNameDescription
Vector3Int[]valuethe value to read

ReadValue(out Vector4)

Read a Vector4

Declaration
public void ReadValue(out Vector4 value)
Parameters
TypeNameDescription
Vector4valuethe value to read

ReadValue(out Vector4[])

Read a Vector4

Declaration
public void ReadValue(out Vector4[] value)
Parameters
TypeNameDescription
Vector4[]valuethe 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
TypeNameDescription
TvalueThe value to read
FastBufferWriter.ForEnumsunusedAn unused parameter used for enabling overload resolution based on generic constraints
Type Parameters
NameDescription
TThe 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
TypeNameDescription
Tvaluethe value to read
FastBufferWriter.ForFixedStringsunusedAn unused parameter used for enabling overload resolution based on generic constraints
Type Parameters
NameDescription
TThe 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
TypeNameDescription
TvalueThe value to read
FastBufferWriter.ForNetworkSerializableunusedAn unused parameter used for enabling overload resolution based on generic constraints
Type Parameters
NameDescription
TThe 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
TypeNameDescription
TvalueThe value to read
FastBufferWriter.ForPrimitivesunusedAn unused parameter used for enabling overload resolution based on generic constraints
Type Parameters
NameDescription
TThe 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
TypeNameDescription
TvalueThe value to read
FastBufferWriter.ForStructsunusedAn unused parameter used for enabling overload resolution based on generic constraints
Type Parameters
NameDescription
TThe 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
TypeNameDescription
T[]valueThe values to read
FastBufferWriter.ForEnumsunusedAn unused parameter used for enabling overload resolution based on generic constraints
Type Parameters
NameDescription
TThe 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
TypeNameDescription
T[]valueThe values to read
FastBufferWriter.ForNetworkSerializableunusedAn unused parameter used for enabling overload resolution based on generic constraints
Type Parameters
NameDescription
TThe 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
TypeNameDescription
T[]valueThe values to read
FastBufferWriter.ForPrimitivesunusedAn unused parameter used for enabling overload resolution based on generic constraints
Type Parameters
NameDescription
TThe 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
TypeNameDescription
T[]valueThe values to read
FastBufferWriter.ForStructsunusedAn unused parameter used for enabling overload resolution based on generic constraints
Type Parameters
NameDescription
TThe type being serialized

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
TypeNameDescription
Colorvaluethe 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
TypeNameDescription
Color[]valuethe 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
TypeNameDescription
Color32valuethe 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
TypeNameDescription
Color32[]valuethe 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
TypeNameDescription
Quaternionvaluethe 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
TypeNameDescription
Quaternion[]valuethe 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
TypeNameDescription
Rayvaluethe 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
TypeNameDescription
Ray[]valuethe 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
TypeNameDescription
Ray2Dvaluethe 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
TypeNameDescription
Ray2D[]valuethe values to read

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
TypeNameDescription
System.StringsStores the read string
System.BooleanoneByteCharsWhether or not to use one byte per character. This will only allow ASCII

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
TypeNameDescription
Vector2valuethe 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
TypeNameDescription
Vector2[]valuethe 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
TypeNameDescription
Vector2Intvaluethe 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
TypeNameDescription
Vector2Int[]valuethe 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
TypeNameDescription
Vector3valuethe 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
TypeNameDescription
Vector3[]valuethe 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
TypeNameDescription
Vector3Intvaluethe 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
TypeNameDescription
Vector3Int[]valuethe 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
TypeNameDescription
Vector4valuethe 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
TypeNameDescription
Vector4[]valuethe 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
TypeNameDescription
TvalueThe value to read
FastBufferWriter.ForEnumsunusedAn unused parameter used for enabling overload resolution based on generic constraints
Type Parameters
NameDescription
TThe 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
TypeNameDescription
Tvaluethe value to read
FastBufferWriter.ForFixedStringsunusedAn unused parameter used for enabling overload resolution based on generic constraints
Type Parameters
NameDescription
TThe 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
TypeNameDescription
TvalueThe value to read
FastBufferWriter.ForNetworkSerializableunusedAn unused parameter used for enabling overload resolution based on generic constraints
Type Parameters
NameDescription
TThe 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
TypeNameDescription
TvalueThe value to read
FastBufferWriter.ForPrimitivesunusedAn unused parameter used for enabling overload resolution based on generic constraints
Type Parameters
NameDescription
TThe 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
TypeNameDescription
TvalueThe value to read
FastBufferWriter.ForStructsunusedAn unused parameter used for enabling overload resolution based on generic constraints
Type Parameters
NameDescription
TThe 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
TypeNameDescription
T[]valueThe values to read
FastBufferWriter.ForEnumsunusedAn unused parameter used for enabling overload resolution based on generic constraints
Type Parameters
NameDescription
TThe 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
TypeNameDescription
T[]valueThe values to read
FastBufferWriter.ForNetworkSerializableunusedAn unused parameter used for enabling overload resolution based on generic constraints
Type Parameters
NameDescription
TThe 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
TypeNameDescription
T[]valueThe value to read
FastBufferWriter.ForPrimitivesunusedAn unused parameter used for enabling overload resolution based on generic constraints
Type Parameters
NameDescription
TThe 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
TypeNameDescription
T[]valueThe values to read
FastBufferWriter.ForStructsunusedAn unused parameter used for enabling overload resolution based on generic constraints
Type Parameters
NameDescription
TThe type being serialized

Seek(Int32)

Move the read position in the stream

Declaration
public void Seek(int where)
Parameters
TypeNameDescription
System.Int32whereAbsolute 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
TypeDescription
System.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
TypeNameDescription
System.Int32bytesAmount of bytes to read
Returns
TypeDescription
System.BooleanTrue if the read is allowed, false otherwise
Exceptions
TypeCondition
System.InvalidOperationExceptionIf 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
TypeNameDescription
TvalueThe value you want to read
Returns
TypeDescription
System.BooleanTrue if the read is allowed, false otherwise
Type Parameters
NameDescription
Tthe type T of the value you are trying to read
Exceptions
TypeCondition
System.InvalidOperationExceptionIf called while in a bitwise context

Implements

System.IDisposable