/// <exception cref="WrxTcpAuthorizationFailedException">Если авторизация не удалась.</exception>
        public static async ValueTask <T> AuthorizeAsync <T>(IPacketWriter <WrxPacket> requestWriter, IPacketReader <WrxPacket> responseReader, IAsyncWrxTcpHubAuthorizer <T> authorizer, ArrayPool <byte> byteArrayPool, CancellationToken cancellationToken = default)
        {
            using var requestPacket = new WrxPacket(0, WrxPacketAction.TcpAuthorizationRequest, 0, _zeroes.AsMemory());
            await requestWriter.WriteAsync(requestPacket, cancellationToken).ConfigureAwait(false);

            using var responsePacket = await responseReader.ReadAsync(cancellationToken).ConfigureAwait(false);

            var(_, responseAction, responseCommand, responseData) = responsePacket;

            if (responseAction != WrxPacketAction.TcpAuthorizationResponse)
            {
                throw new Exception("Invalid action.");
            }

            if (responseCommand != 0)
            {
                throw new Exception("Invalid command.");
            }

            var authorizationData = WrxTcpAuthorizationData.Read(responseData.Span);
            var info = await authorizer.ValidateDataAsync(authorizationData, cancellationToken).ConfigureAwait(false);

            using var acknowledgementPacket = new WrxPacket(1, WrxPacketAction.TcpAuthorizationRequest, 1, _zeroes.AsMemory());
            await requestWriter.WriteAsync(acknowledgementPacket, cancellationToken).ConfigureAwait(false);

            return(info);
        }
        public static async ValueTask AuthorizeAsync(IPacketReader <WrxPacket> requestReader, IPacketWriter <WrxPacket> responseWriter, IAsyncWrxTcpDeviceAuthorizer authorizer, ArrayPool <byte> byteArrayPool, CancellationToken cancellationToken = default)
        {
            using var requestPacket = await requestReader.ReadAsync(cancellationToken).ConfigureAwait(false);

            var(protocol, requestAction, requestCommand, _) = requestPacket;

            if (requestAction != WrxPacketAction.TcpAuthorizationRequest)
            {
                throw new Exception();
            }

            if (requestCommand != 0)
            {
                throw new Exception();
            }

            var byteArray = byteArrayPool.Rent(WrxTcpAuthorizationData.Size);

            try
            {
                var bytes = byteArray.AsMemory();
                (await authorizer.ProvideDataAsync(cancellationToken).ConfigureAwait(false)).Write(bytes.Span);
                using var responsePacket = new WrxPacket(protocol, WrxPacketAction.TcpAuthorizationResponse, 0, bytes[..WrxTcpAuthorizationData.Size]);