using System.IO;

namespace Crysome.Common.Network.Packets.Client;

public class ReverseProxyDataPacket : IPacket
{
	public int ConnectionId { get; set; }

	public byte[] Data { get; set; }

	public ReverseProxyDataPacket()
	{
	}

	public ReverseProxyDataPacket(int connectionId, byte[] data)
	{
		ConnectionId = connectionId;
		Data = data ?? new byte[0];
	}

	public void Write(BinaryWriter w)
	{
		w.Write(ConnectionId);
		w.Write((Data != null) ? Data.Length : 0);
		if (Data != null && Data.Length != 0)
		{
			w.Write(Data);
		}
	}

	public void Read(BinaryReader r)
	{
		ConnectionId = r.ReadInt32();
		int num = r.ReadInt32();
		Data = ((num > 0) ? r.ReadBytes(num) : new byte[0]);
	}
}
