Struct NativeStream.Reader
Reads data from a buffer of a NativeStream.
Namespace: Unity.Collections
Syntax
[NativeContainer]
[NativeContainerIsReadOnly]
public struct 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 readonly int ForEachCount { get; }
Property Value
Type | Description |
---|---|
Int32 | The number of buffers in the stream of this reader. |
RemainingItemCount
The number of items not yet read from the buffer.
Declaration
public readonly int RemainingItemCount { get; }
Property Value
Type | Description |
---|---|
Int32 | The number of items not yet read from the buffer. |
Methods
BeginForEachIndex(Int32)
Readies this reader to read a particular buffer of the stream.
Declaration
public int BeginForEachIndex(int foreachIndex)
Parameters
Type | Name | Description |
---|---|---|
Int32 | foreachIndex | The index of the buffer to read. |
Returns
Type | Description |
---|---|
Int32 | 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 EndForEachIndex().
Count()
Returns the total number of items in the buffers of the stream.
Declaration
public int Count()
Returns
Type | Description |
---|---|
Int32 | 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 : struct
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. |
Read<T>()
Reads the next value from the buffer.
Declaration
public ref T Read<T>()
where T : struct
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. |
ReadUnsafePtr(Int32)
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 |
---|---|---|
Int32 | 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. |