using System.IO;

namespace Crysome.Common.Network.Packets.Client;

public class AudioStreamChunkPacket : IPacket
{
	public byte[] Chunk { get; set; } = new byte[0];

	public AudioStreamChunkPacket()
	{
	}

	public AudioStreamChunkPacket(byte[] chunk)
	{
		Chunk = chunk ?? new byte[0];
	}

	public void Write(BinaryWriter w)
	{
		byte[] chunk = Chunk;
		w.Write((chunk != null) ? chunk.Length : 0);
		if (Chunk != null && Chunk.Length != 0)
		{
			w.Write(Chunk);
		}
	}

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