using System;
using System.IO;
using Crysome.Common.Network.Packets;

namespace Crysome.Common.Network.FileTransfer;

public sealed class FtChunkPacket : IPacket
{
	public uint TransferId;

	public int ChunkIdx;

	public uint Crc32;

	public byte[] Data;

	public void Write(BinaryWriter w)
	{
		w.Write(TransferId);
		w.Write(ChunkIdx);
		w.Write(Crc32);
		int num = ((Data != null) ? Data.Length : 0);
		w.Write(num);
		if (num > 0)
		{
			w.Write(Data);
		}
	}

	public void Read(BinaryReader r)
	{
		TransferId = r.ReadUInt32();
		ChunkIdx = r.ReadInt32();
		Crc32 = r.ReadUInt32();
		int num = r.ReadInt32();
		Data = ((num > 0) ? r.ReadBytes(num) : Array.Empty<byte>());
	}
}
