Struct DataStreamReader
The DataStreamReader
class is the counterpart of the
DataStreamWriter
class and can be be used to deserialize
data which was prepared with it.
Inherited Members
Namespace: Unity.Networking.Transport
Assembly: solution.dll
Syntax
public struct DataStreamReader
Remarks
Simple usage example:
using (var dataWriter = new DataStreamWriter(16, Allocator.Persistent))
{
dataWriter.Write(42);
dataWriter.Write(1234);
// Length is the actual amount of data inside the writer,
// Capacity is the total amount.
var dataReader = new DataStreamReader(dataWriter, 0, dataWriter.Length);
var context = default(DataStreamReader.Context);
var myFirstInt = dataReader.ReadInt(ref context);
var mySecondInt = dataReader.ReadInt(ref context);
}
The DataStreamReader
carries the position of the read pointer inside the struct,
taking a copy of the reader will also copy the read position. This includes passing the
reader to a method by value instead of by ref.
See the Data
Constructors
Name | Description |
---|---|
Data |
Initializes a new instance of the DataStreamReader struct with a pointer and length. |
Data |
Initializes a new instance of the DataStreamReader struct with a NativeArray<byte>. |
Properties
Name | Description |
---|---|
Has |
If there is a read failure this returns true. A read failure might happen if this attempts to read more than there is capacity for. |
Is |
True if the reader has been pointed to a valid buffer space. This would be false if the reader was created with no arguments. |
Is |
Show the byte order in which the current computer architecture stores data. |
Length | The total size of the buffer space this reader is working with. |
Methods
Name | Description |
---|---|
Get |
Gets the number of bits read from the data stream. |
Get |
Gets the number of bytes read from the data stream. |
Get |
Get a pointer to the stream's data. Note that the pointer always points at the beginning of the data, no matter how much was read from the stream. |
Read |
Reads an unsigned byte from the current stream and advances the current position of the stream by one byte. |
Read |
Read the requested number of bytes to the given pointer. |
Read |
Read and copy data into the given NativeArray of bytes. The number of bytes read is the length of the provided array. |
Read |
Read and copy a fixed string (of unknown length) into the given buffer. |
Read |
Reads a |
Read |
Reads a |
Read |
Reads a |
Read |
Reads a |
Read |
Reads a |
Read |
Reads a 4-byte floating point value from the current stream and advances the current position of the stream by four bytes. |
Read |
Reads a 4-byte signed integer from the current stream and advances the current position of the stream by four bytes. |
Read |
Reads a 4-byte signed integer from the current stream in Big-endian byte order and advances the current position of the stream by four bytes. If the current endianness is in little-endian order, the byte order will be swapped. |
Read |
Reads an 8-byte signed long from the stream and advances the current position of the stream by eight bytes. |
Read |
Reads a |
Read |
Reads a |
Read |
Reads a |
Read |
Reads a |
Read |
Reads a |
Read |
Read and copy a fixed string delta (of unknown length) into the given buffer. |
Read |
Reads a 4-byte floating point value from the data stream using a Network |
Read |
Reads a 4-byte floating point value from the data stream. If the first bit is 0, the data did not change and |
Read |
Reads a 4-byte signed integer value from the data stream using a Network |
Read |
Reads a 4-byte signed integer delta value from the data stream using a Network |
Read |
Reads an 8-byte signed long value from the data stream using a Network |
Read |
Reads an 8-byte signed long delta value from the data stream using a Network |
Read |
Reads a 4-byte unsigned integer from the current stream using a Network |
Read |
Reads a 4-byte unsigned integer delta value from the data stream using a Network |
Read |
Reads an 8-byte unsigned long value from the data stream using a Network |
Read |
Reads an 8-byte unsigned long delta value from the data stream using a Network |
Read |
Reads a specified number of bits from the data stream. |
Read |
Reads a 2-byte signed short from the current stream and advances the current position of the stream by two bytes. |
Read |
Reads a 2-byte signed short from the current stream in Big-endian byte order and advances the current position of the stream by two bytes. If the current endianness is in little-endian order, the byte order will be swapped. |
Read |
Reads a 4-byte unsigned integer from the current stream and advances the current position of the stream by four bytes. |
Read |
Reads a 4-byte unsigned integer from the current stream in Big-endian byte order and advances the current position of the stream by four bytes. If the current endianness is in little-endian order, the byte order will be swapped. |
Read |
Reads an 8-byte unsigned long from the stream and advances the current position of the stream by eight bytes. |
Read |
Reads a 2-byte unsigned short from the current stream and advances the current position of the stream by two bytes. |
Read |
Reads a 2-byte unsigned short from the current stream in Big-endian byte order and advances the current position of the stream by two bytes. If the current endianness is in little-endian order, the byte order will be swapped. |
Seek |
Sets the current position of this stream to the given value.
An error will be logged if |