Struct UnsafeStream.Reader
Reads data from a buffer of an UnsafeStream.
Namespace: Unity.Collections.LowLevel.Unsafe
Assembly: Unity.Collections.dll
Syntax
public struct UnsafeStream.Reader
Remarks
An individual reader can only be used for one buffer of one stream. Do not create more than one reader for an individual buffer.
Properties
ForEachCount
The number of buffers in the stream of this reader.
Declaration
public int ForEachCount { get; }
Property Value
Type | Description |
---|---|
int | The number of buffers in the stream of this reader. |
RemainingItemCount
The number of items not yet read from the buffer.
Declaration
public int RemainingItemCount { get; }
Property Value
Type | Description |
---|---|
int | The number of items not yet read from the buffer. |
Methods
BeginForEachIndex(int)
Readies this reader to read a particular buffer of the stream.
Declaration
public int BeginForEachIndex(int foreachIndex)
Parameters
Type | Name | Description |
---|---|---|
int | foreachIndex | The index of the buffer to read. |
Returns
Type | Description |
---|---|
int | The number of remaining elements to read from the buffer. |
Remarks
Must be called before using this reader. For an individual reader, call this method only once.
When done using this reader, you must call <xref href="Unity.Collections.LowLevel.Unsafe.UnsafeStream.Reader.EndForEachIndex" data-throw-if-not-resolved="false"></xref>.
Count()
Returns the total number of items in the buffers of the stream.
Declaration
public int Count()
Returns
Type | Description |
---|---|
int | The total number of items in the buffers of the stream. |
EndForEachIndex()
Does nothing.
Declaration
public void EndForEachIndex()
Remarks
Included only for consistency with NativeStream.
Peek<T>()
Reads the next value from the buffer. Does not advance the reader.
Declaration
public ref T Peek<T>() where T : unmanaged
Returns
Type | Description |
---|---|
T | A reference to the next value from the buffer. |
Type Parameters
Name | Description |
---|---|
T | The type of value to read. |
ReadUnsafePtr(int)
Returns a pointer to the next position to read from the buffer. Advances the reader some number of bytes.
Declaration
public byte* ReadUnsafePtr(int size)
Parameters
Type | Name | Description |
---|---|---|
int | size | The number of bytes to advance the reader. |
Returns
Type | Description |
---|---|
byte* | A pointer to the next position to read from the buffer. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if the reader has been advanced past the end of the buffer. |
Read<T>()
Reads the next value from the buffer.
Declaration
public ref T Read<T>() where T : unmanaged
Returns
Type | Description |
---|---|
T | A reference to the next value from the buffer. |
Type Parameters
Name | Description |
---|---|
T | The type of value to read. |
Remarks
Each read advances the reader to the next item in the buffer.