Struct FastBufferReader
Optimized class used for reading values from a byte stream
Fast
Implements
Inherited Members
Namespace: Unity.Netcode
Assembly: solution.dll
Syntax
public struct FastBufferReader : IDisposable
Constructors
Name | Description |
---|---|
Fast |
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. |
Fast |
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. |
Fast |
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. |
Fast |
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. |
Fast |
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). |
Fast |
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. |
Properties
Name | Description |
---|---|
Is |
Gets a value indicating whether the reader has been initialized and a handle allocated. |
Length | Get the total length of the buffer |
Position | Get the current read position |
Methods
Name | Description |
---|---|
Dispose() | IDisposable implementation that frees the allocated buffer |
Enter |
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. |
Get |
Gets a direct pointer to the underlying buffer |
Get |
Gets a direct pointer to the underlying buffer at the current read position |
Read |
Read a byte to the stream. |
Read |
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. |
Read |
Read multiple bytes to the stream |
Read |
Read multiple bytes from the stream |
Read |
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. |
Read |
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. |
Read |
Read an INetworkSerializable in-place, without constructing a new one Note that this will NOT check for null before calling NetworkSerialize |
Read |
Read a NativeArray of INetworkSerializables |
Read |
Read an INetworkSerializable |
Read |
Read an array of INetworkSerializables |
Read |
Read a partial value. The value is zero-initialized and then the specified number of bytes is read into it. |
Read |
Reads a string NOTE: ALLOCATES |
Read |
Read a Color32 |
Read |
Read a Color32 array |
Read |
Read a Color |
Read |
Read a Color array |
Read |
Read a Quaternion |
Read |
Read a Quaternion array |
Read |
Read a Ray2D |
Read |
Read a Ray2D array |
Read |
Read a Ray |
Read |
Read a Ray array |
Read |
Read a Vector2 |
Read |
Read a Vector2Int |
Read |
Read a Vector2Int array |
Read |
Read a Vector2 array |
Read |
Read a Vector3 |
Read |
Read a Vector3Int |
Read |
Read a Vector3Int array |
Read |
Read a Vector3 array |
Read |
Read a Vector4 |
Read |
Read a Vector4 |
Read |
Reads a string. NOTE: ALLOCATES "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Color32 "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Color32 array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Color "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Collor array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Quaternion "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Quaternion array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Ray2D "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Ray2D array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Ray "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Ray array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Vector2 "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Vector2Int "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Vector2Int array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Vector2 array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Vector3 "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Vector3Int "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Vector3Int array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Vector3 array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Vector4 "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a Vector4 array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a FixedString value. "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
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. |
Read |
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. |
Read |
Read a FixedString NativeArray. "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a struct NativeArray "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a NetworkSerializable NativeArray "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read an enum value "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a FixedString value. "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a NetworkSerializable value "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
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. |
Read |
Read a struct "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read an enum array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
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. |
Read |
Read a NetworkSerializable array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
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. |
Read |
Read a struct array "Safe" version - automatically performs bounds checking. Less efficient than bounds checking for multiple reads at once by calling TryBeginRead. |
Read |
Read a struct NativeArray using a Temp allocator. Equivalent to ReadValue(out value, Allocator.Temp) |
Read |
Read a struct NativeArray |
Read |
Read an enum value |
Read |
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) |
Read |
Read a NetworkSerializable value |
Read |
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. |
Read |
Read a struct |
Read |
Read an enum array |
Read |
Read a NetworkSerializable array |
Read |
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. |
Read |
Read a struct array |
Seek(int) | Move the read position in the stream |
To |
Returns an array representation of the underlying byte buffer. !!Allocates a new array!! |
Try |
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. |
Try |
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. |