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
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.