예제 #1
0
        async Task Handle_Close(ReadOnlySequence <byte> arguments)
        {
            IsOpen = false;

            await methods.Send_CloseOk();

            if (replyIsExpected)
            {
                SendReply();
            }

            void SendReply()
            {
                var reader = new CustomBufferReader(arguments);

                var replyCode = reader.ReadUInt16();
                var replyText = reader.ReadShortString();

                var method = reader.ReadUInt32();

                var classId  = method >> 16;
                var methodId = method << 16 >> 16;

                var exception = new Exception($"Channel Closed: {replyCode} {replyText}. ClassId: {classId} MethodId: {methodId}");

                replyHandler(replyTaskCompletionSource, default, exception);
예제 #2
0
        internal async Task Handle_ContentHeader(ReadOnlySequence <byte> payload)
        {
            ulong Read()
            {
                var reader = new CustomBufferReader(payload);

                var classId  = reader.ReadUInt16();
                var weight   = reader.ReadUInt16();
                var bodySize = reader.ReadUInt64();

                pendingDelivery.Properties = reader.ReadBasicProperties();

                return(bodySize);
            }

            var size = Read();

            if (size == 0)
            {
                pendingDelivery.Body = new byte[0];

                await consumers[pendingDelivery.ConsumerTag](pendingDelivery);
                pendingDelivery = null;
            }
        }
예제 #3
0
        internal Task Handle_Deliver(ReadOnlySequence <byte> arguments)
        {
            var reader = new CustomBufferReader(arguments);

            pendingDelivery = new DeliverState
            {
                ConsumerTag = reader.ReadShortString(),
                DeliveryTag = reader.ReadUInt64(),
                Redelivered = Convert.ToBoolean(reader.ReadByte()),
                Exchange    = reader.ReadShortString(),
                RoutingKey  = reader.ReadShortString()
            };

            return(Task.CompletedTask);
        }
예제 #4
0
        void Handle_CancelOk(object tcs, ReadOnlySequence <byte> arguments, Exception exception)
        {
            var cancelOk = (TaskCompletionSource <string>)tcs;

            if (exception != null)
            {
                cancelOk.SetException(exception);
            }
            else
            {
                var reader      = new CustomBufferReader(arguments);
                var consumerTag = reader.ReadShortString();
                cancelOk.SetResult(consumerTag);
            }
        }
예제 #5
0
        void Handle_DeleteOk(object tcs, ReadOnlySequence <byte> arguments, Exception exception)
        {
            var deleteOk = (TaskCompletionSource <uint>)tcs;

            if (exception != null)
            {
                deleteOk.SetException(exception);
            }
            else
            {
                var reader       = new CustomBufferReader(arguments);
                var messageCount = reader.ReadUInt32();
                deleteOk.SetResult(messageCount);
            }
        }
예제 #6
0
        void Handle_DeclareOk(object tcs, ReadOnlySequence <byte> arguments, Exception exception)
        {
            var declareOk = (TaskCompletionSource <DeclareResult>)tcs;

            if (exception != null)
            {
                declareOk.SetException(exception);
            }
            else
            {
                var reader = new CustomBufferReader(arguments);

                DeclareResult result;

                result.QueueName     = reader.ReadShortString();
                result.MessageCount  = reader.ReadUInt32();
                result.ConsumerCount = reader.ReadUInt32();

                declareOk.SetResult(result);
            }
        }