Struct NativeStream.Reader
Reads data from a buffer of a NativeStream.
Namespace: Unity.Collections
Assembly: Unity.Collections.dll
Syntax
[NativeContainer]
[NativeContainerIsReadOnly]
public struct NativeStream.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 elements left 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.NativeStream.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()
Checks if all data has been read from the buffer.
Declaration
public void EndForEachIndex()
Remarks
If you intentionally don't want to read all the data in the buffer, don't call this method. Otherwise, calling this method is recommended, even though it's not strictly necessary.
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if not all the buffer's data has been read. |
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. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if the read would go past the end of the buffer. |
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 would advance 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.
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if the reader would advance past the end of the buffer. |