Class DataStreamExtensions
Extension methods for DataStream.
Namespace: Unity.Collections.LowLevel.Unsafe
Assembly: Unity.Collections.dll
Syntax
public static class DataStreamExtensions
Methods
Create(byte*, int)
Initializes a new instance of the DataStreamWriter struct with externally owned memory
Declaration
public static DataStreamWriter Create(byte* data, int length)
Parameters
Type | Name | Description |
---|---|---|
byte* | data | Pointer to the data |
int | length | Length of the data |
Returns
Type | Description |
---|---|
DataStreamWriter | A new instance of the DataStreamWriter |
ReadBytesUnsafe(ref DataStreamReader, byte*, int)
Read and copy data to the memory location pointed to, an error will
be logged if the length
will put the reader out of bounds on the current read pointer.
Declaration
public static void ReadBytesUnsafe(this ref DataStreamReader reader, byte* data, int length)
Parameters
Type | Name | Description |
---|---|---|
DataStreamReader | reader | Data stream reader. |
byte* | data | Pointer to the data. |
int | length | Number of bytes to read. |
ReadFixedStringUnsafe(ref DataStreamReader, byte*, int)
Reads a 2-byte length value from the current stream, reads the specified number of bytes to the buffer and advances the current position of the stream by the length of the string.
Declaration
public static ushort ReadFixedStringUnsafe(this ref DataStreamReader reader, byte* data, int maxLength)
Parameters
Type | Name | Description |
---|---|---|
DataStreamReader | reader | Data stream reader. |
byte* | data | Buffer to write the string bytes to. |
int | maxLength | Max number of bytes allowed to be read into the buffer. |
Returns
Type | Description |
---|---|
ushort | The number of bytes written to the data buffer. |
ReadPackedFixedStringDeltaUnsafe(ref DataStreamReader, byte*, int, byte*, ushort, StreamCompressionModel)
Writes a delta FixedString value to the data stream using a StreamCompressionModel.
If the value cannot be written HasFailedReads will return true.
Declaration
public static ushort ReadPackedFixedStringDeltaUnsafe(this ref DataStreamReader reader, byte* data, int maxLength, byte* baseData, ushort baseLength, StreamCompressionModel model)
Parameters
Type | Name | Description |
---|---|---|
DataStreamReader | reader | Data stream reader. |
byte* | data | Pointer to a packed fixed string. |
int | maxLength | Max number of bytes allowed to be read into the pointer. |
byte* | baseData | Pointer to the previous value, used to compute the diff. |
ushort | baseLength | The length of the previous value. |
StreamCompressionModel | model | StreamCompressionModel model for writing value in a packed manner. |
Returns
Type | Description |
---|---|
ushort | Whether the write was successful |
WriteBytesUnsafe(ref DataStreamWriter, byte*, int)
Appends a specified number of bytes from the buffer to the data stream.
Declaration
public static bool WriteBytesUnsafe(this ref DataStreamWriter writer, byte* data, int bytes)
Parameters
Type | Name | Description |
---|---|---|
DataStreamWriter | writer | Data stream writer. |
byte* | data | Pointer to the data. |
int | bytes | A positive number of bytes to write. |
Returns
Type | Description |
---|---|
bool | Whether the write was successful |