using NATS.Server.Mqtt;

namespace NATS.Server.Mqtt.Tests.Mqtt;

public class MqttPacketWriterTests
{
    [Fact]
    public void Writer_emits_fixed_header_and_round_trips_with_reader()
    {
        byte[] payload = Enumerable.Repeat((byte)0xAB, 130).ToArray();

        var encoded = MqttPacketWriter.Write(MqttControlPacketType.Publish, payload);
        encoded[0].ShouldBe((byte)0x30); // PUBLISH type with default flags

        var decoded = MqttPacketReader.Read(encoded);
        decoded.Type.ShouldBe(MqttControlPacketType.Publish);
        decoded.RemainingLength.ShouldBe(payload.Length);
        decoded.Payload.ToArray().ShouldBe(payload);
    }
}
