protected bool ReadChunkHeader(DataStreamReader stream, ref DataStreamReader.Context ctx , out DataStreamReader chunk, out DataStreamReader.Context ctx2, out ushort targetPlayerId, out ushort senderPlayerId) { chunk = default; ctx2 = default; targetPlayerId = 0; senderPlayerId = 0; int pos = stream.GetBytesRead(ref ctx); if (pos >= stream.Length) { return(false); } ushort dataLength = stream.ReadUShort(ref ctx); if (dataLength == 0) { return(false); } chunk = stream.ReadChunk(ref ctx, dataLength); targetPlayerId = chunk.ReadUShort(ref ctx2); senderPlayerId = chunk.ReadUShort(ref ctx2); return(true); }
public void Execute() { var reader = new DataStreamReader(packetChunks, 0, packetChunks.Length); var ctx = default(DataStreamReader.Context); for (int i = 0; i < packetLengths.Length; i++) { ushort packetDataLen = packetLengths[i]; if (packetDataLen == 0) { continue; } var packet = reader.ReadChunk(ref ctx, packetDataLen); using (var temp = new DataStreamWriter(packetDataLen, Allocator.Temp)) { unsafe { byte *packetPtr = packet.GetUnsafeReadOnlyPtr(); temp.WriteBytes(packetPtr, packetDataLen); } //Debug.Log ("SendUnreliableChunksJob ChunkIndex = " + i + ", packetDataLen=" + packetDataLen); connection.Send(driver, temp); } } }