Struct DataStreamWriter
Data streams can be used to serialize data over the network. The
DataStreamWriter
and DataStreamReader
classes work together
to serialize data for sending and then to deserialize when receiving.
Syntax
public struct DataStreamWriter : IDisposable
Constructors
DataStreamWriter(Int32, Allocator)
Declaration
public DataStreamWriter(int capacity, Allocator allocator)
Parameters
Type |
Name |
Description |
Int32 |
capacity |
|
Allocator |
allocator |
|
Properties
Capacity
The total size of the data buffer, see Length for
the size of space used in the buffer. Capacity can be
changed after the writer has been created.
Declaration
public int Capacity { get; set; }
Property Value
Exceptions
IsCreated
True if there is a valid data buffer present. This would be false
if the writer was created with no arguments.
Declaration
public bool IsCreated { get; }
Property Value
Length
The size of the buffer used. See Capacity for the total size.
Declaration
public int Length { get; }
Property Value
LengthInBits
The size of the buffer used in bits. See Length for the length in bytes.
Declaration
public int LengthInBits { get; }
Property Value
Methods
Clear()
Moves the write position to the start of the data buffer used.
Declaration
CopyTo(Int32, Int32, NativeArray<Byte>)
Copy data from the writer to the given NativeArray, the data size
(start to length) must not exceed the total size of the array or
an exception will be thrown.
Declaration
public void CopyTo(int start, int length, NativeArray<byte> dest)
Parameters
CopyTo(Int32, Int32, ref Byte[])
Copy data from the writer to the given managed byte array, the
data size (start to length) must not exceed the total size of the
byte array or an exception will be thrown.
Declaration
public void CopyTo(int start, int length, ref byte[] dest)
Parameters
Dispose()
The writer uses unmanaged memory for its data buffer. Dispose
needs to be called to free this resource.
Declaration
Flush()
Declaration
GetNativeSlice(Int32, Int32)
Create a NativeSlice with access to the raw data in the writer, the data size
(start to length) must not exceed the total size of the array or
an exception will be thrown.
Declaration
public NativeSlice<byte> GetNativeSlice(int start, int length)
Parameters
Returns
Type |
Description |
NativeSlice<Byte> |
|
Write(Byte)
Declaration
public DataStreamWriter.DeferredByte Write(byte value)
Parameters
Type |
Name |
Description |
Byte |
value |
|
Returns
Write(Byte[], Int32)
Copy byte array into the writers data buffer, up to the
given length or the complete size if no length (or -1) is given.
Declaration
public void Write(byte[] value, int length = -1)
Parameters
Type |
Name |
Description |
Byte[] |
value |
Source byte array
|
Int32 |
length |
Length to copy, omit this to copy all the byte array
|
Write(Int16)
Declaration
public DataStreamWriter.DeferredShort Write(short value)
Parameters
Type |
Name |
Description |
Int16 |
value |
|
Returns
Write(Int32)
Declaration
public DataStreamWriter.DeferredInt Write(int value)
Parameters
Type |
Name |
Description |
Int32 |
value |
|
Returns
Write(Single)
Declaration
public DataStreamWriter.DeferredFloat Write(float value)
Parameters
Type |
Name |
Description |
Single |
value |
|
Returns
Write(UInt16)
Declaration
public DataStreamWriter.DeferredUShort Write(ushort value)
Parameters
Type |
Name |
Description |
UInt16 |
value |
|
Returns
Write(UInt32)
Declaration
public DataStreamWriter.DeferredUInt Write(uint value)
Parameters
Type |
Name |
Description |
UInt32 |
value |
|
Returns
Write(UInt64)
Declaration
public void Write(ulong value)
Parameters
Type |
Name |
Description |
UInt64 |
value |
|
WriteBytes(Byte*, Int32)
Declaration
public void WriteBytes(byte *data, int bytes)
Parameters
WriteNetworkByteOrder(Int16)
Declaration
public DataStreamWriter.DeferredShortNetworkByteOrder WriteNetworkByteOrder(short value)
Parameters
Type |
Name |
Description |
Int16 |
value |
|
Returns
WriteNetworkByteOrder(Int32)
Declaration
public DataStreamWriter.DeferredIntNetworkByteOrder WriteNetworkByteOrder(int value)
Parameters
Type |
Name |
Description |
Int32 |
value |
|
Returns
WriteNetworkByteOrder(UInt16)
Declaration
public DataStreamWriter.DeferredUShortNetworkByteOrder WriteNetworkByteOrder(ushort value)
Parameters
Type |
Name |
Description |
UInt16 |
value |
|
Returns
WriteNetworkByteOrder(UInt32)
Declaration
public DataStreamWriter.DeferredUIntNetworkByteOrder WriteNetworkByteOrder(uint value)
Parameters
Type |
Name |
Description |
UInt32 |
value |
|
Returns
WritePackedFloat(Single, NetworkCompressionModel)
Declaration
public void WritePackedFloat(float value, NetworkCompressionModel model)
Parameters
WritePackedFloatDelta(Single, Single, NetworkCompressionModel)
Declaration
public void WritePackedFloatDelta(float value, float baseline, NetworkCompressionModel model)
Parameters
WritePackedInt(Int32, NetworkCompressionModel)
Declaration
public void WritePackedInt(int value, NetworkCompressionModel model)
Parameters
WritePackedIntDelta(Int32, Int32, NetworkCompressionModel)
Declaration
public void WritePackedIntDelta(int value, int baseline, NetworkCompressionModel model)
Parameters
WritePackedStringDelta(NativeString64, NativeString64, NetworkCompressionModel)
Declaration
public void WritePackedStringDelta(NativeString64 str, NativeString64 baseline, NetworkCompressionModel model)
Parameters
WritePackedUInt(UInt32, NetworkCompressionModel)
Declaration
public void WritePackedUInt(uint value, NetworkCompressionModel model)
Parameters
WritePackedUIntDelta(UInt32, UInt32, NetworkCompressionModel)
Declaration
public void WritePackedUIntDelta(uint value, uint baseline, NetworkCompressionModel model)
Parameters
WriteString(NativeString64)
Declaration
public void WriteString(NativeString64 str)
Parameters
Type |
Name |
Description |
NativeString64 |
str |
|
Extension Methods