NetworkWriter
Growable little-endian byte writer used for every Nebula message.
Nebula · Packages/com.1by3.nebula/Runtime/Serialization/NetworkWriter.cspublic sealed class NetworkWriterGrowable little-endian byte writer used for every Nebula message. Deliberately plain: no bit packing or quantisation yet - bandwidth is not the prototype's problem, correctness is. Reuse instances; call Reset between messages.
Constructors
NetworkWriter
public NetworkWriter(int capacity = 1024);Properties
Position
public int Position { get; }Length
public int Length { get; }Buffer
public byte[] Buffer { get; }Methods
Reset
public void Reset();Rewind
public void Rewind(int length);Drop everything written after length (a value from Length).
ToSegment
public ArraySegment<byte> ToSegment();ToArray
public byte[] ToArray();WriteByte
public void WriteByte(byte value);WriteBool
public void WriteBool(bool value);WriteSByte
public void WriteSByte(sbyte value);WriteUShort
public void WriteUShort(ushort value);WriteShort
public void WriteShort(short value);WriteUInt
public void WriteUInt(uint value);WriteInt
public void WriteInt(int value);WriteULong
public void WriteULong(ulong value);WriteLong
public void WriteLong(long value);WriteFloat
public void WriteFloat(float value);WriteDouble
public void WriteDouble(double value);WriteString
public void WriteString(string value);WriteBytes
public void WriteBytes(ArraySegment<byte> bytes);
public void WriteBytes(byte[] bytes);Length-prefixed byte blob (ushort length).
WriteRaw
public void WriteRaw(ArraySegment<byte> bytes);Raw bytes with no length prefix.
WriteVector2
public void WriteVector2(Vector2 v);WriteVector3
public void WriteVector3(Vector3 v);WriteQuaternion
public void WriteQuaternion(Quaternion q);WriteHalf
public void WriteHalf(float value);IEEE half (2 bytes). ~3 significant digits: fine for positions within a few hundred metres and for unit-range values.
WriteCompressedQuaternion
public void WriteCompressedQuaternion(Quaternion q);Smallest-three quaternion compression: 4 bytes instead of 16. The largest component is dropped (its sign is normalised away) and the other three are quantised to 10 bits each in [-1/sqrt2, 1/sqrt2]; worst-case error is about 0.1 degrees.
WriteColor
public void WriteColor(Color c);ReserveUShort
public int ReserveUShort();Reserve a ushort slot to be patched later (e.g. a count written after a loop).
PatchUShort
public void PatchUShort(int at, ushort value);