diff --git a/projects/RabbitMQ.Client/client/impl/CommandAssembler.cs b/projects/RabbitMQ.Client/client/impl/CommandAssembler.cs index b031243a56..2d1d0eee79 100644 --- a/projects/RabbitMQ.Client/client/impl/CommandAssembler.cs +++ b/projects/RabbitMQ.Client/client/impl/CommandAssembler.cs @@ -72,7 +72,7 @@ public CommandAssembler(ProtocolBase protocol) Reset(); } - public Command HandleFrame(InboundFrame f) + public Command HandleFrame(in InboundFrame f) { switch (m_state) { diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index 5ee703bbef..2e6c200a5f 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -586,7 +586,7 @@ public void MainLoopIteration() // quiescing situation, even though technically we // should be ignoring everything except // connection.close-ok. - _session0.HandleFrame(frame); + _session0.HandleFrame(in frame); } else { @@ -608,7 +608,7 @@ public void MainLoopIteration() } else { - session.HandleFrame(frame); + session.HandleFrame(in frame); } } } diff --git a/projects/RabbitMQ.Client/client/impl/Frame.cs b/projects/RabbitMQ.Client/client/impl/Frame.cs index c4308815b1..073c9dfcc1 100644 --- a/projects/RabbitMQ.Client/client/impl/Frame.cs +++ b/projects/RabbitMQ.Client/client/impl/Frame.cs @@ -165,10 +165,17 @@ internal int GetMinimumBufferSize() } } - class InboundFrame : Frame, IDisposable + internal readonly struct InboundFrame : IDisposable { - private InboundFrame(FrameType type, int channel, ReadOnlyMemory payload) : base(type, channel, payload) + public readonly ReadOnlyMemory Payload; + public readonly int Channel; + public readonly FrameType Type; + + private InboundFrame(FrameType type, int channel, ReadOnlyMemory payload) { + Payload = payload; + Type = type; + Channel = channel; } public bool IsMethod() @@ -289,6 +296,11 @@ public void Dispose() ArrayPool.Shared.Return(segment.Array); } } + + public override string ToString() + { + return $"(type={Type}, channel={Channel}, {Payload.Length} bytes of payload)"; + } } class Frame diff --git a/projects/RabbitMQ.Client/client/impl/ISession.cs b/projects/RabbitMQ.Client/client/impl/ISession.cs index e9ad5ea76f..baf411a731 100644 --- a/projects/RabbitMQ.Client/client/impl/ISession.cs +++ b/projects/RabbitMQ.Client/client/impl/ISession.cs @@ -78,7 +78,7 @@ interface ISession void Close(ShutdownEventArgs reason); void Close(ShutdownEventArgs reason, bool notify); - void HandleFrame(InboundFrame frame); + void HandleFrame(in InboundFrame frame); void Notify(); void Transmit(Command cmd); void Transmit(IList cmd); diff --git a/projects/RabbitMQ.Client/client/impl/MainSession.cs b/projects/RabbitMQ.Client/client/impl/MainSession.cs index 1bb86f95b2..e440a04d3f 100644 --- a/projects/RabbitMQ.Client/client/impl/MainSession.cs +++ b/projects/RabbitMQ.Client/client/impl/MainSession.cs @@ -71,13 +71,13 @@ public MainSession(Connection connection) : base(connection, 0) public Action Handler { get; set; } - public override void HandleFrame(InboundFrame frame) + public override void HandleFrame(in InboundFrame frame) { lock (_closingLock) { if (!_closing) { - base.HandleFrame(frame); + base.HandleFrame(in frame); return; } } @@ -88,7 +88,7 @@ public override void HandleFrame(InboundFrame frame) if ((method.ProtocolClassId == _closeClassId) && (method.ProtocolMethodId == _closeMethodId)) { - base.HandleFrame(frame); + base.HandleFrame(in frame); return; } diff --git a/projects/RabbitMQ.Client/client/impl/QuiescingSession.cs b/projects/RabbitMQ.Client/client/impl/QuiescingSession.cs index c8bc6a859f..633426b133 100644 --- a/projects/RabbitMQ.Client/client/impl/QuiescingSession.cs +++ b/projects/RabbitMQ.Client/client/impl/QuiescingSession.cs @@ -55,7 +55,7 @@ public QuiescingSession(Connection connection, m_reason = reason; } - public override void HandleFrame(InboundFrame frame) + public override void HandleFrame(in InboundFrame frame) { if (frame.IsMethod()) { diff --git a/projects/RabbitMQ.Client/client/impl/Session.cs b/projects/RabbitMQ.Client/client/impl/Session.cs index 6aa7b59e6e..b448984ad7 100644 --- a/projects/RabbitMQ.Client/client/impl/Session.cs +++ b/projects/RabbitMQ.Client/client/impl/Session.cs @@ -53,9 +53,9 @@ public Session(Connection connection, int channelNumber) _assembler = new CommandAssembler(connection.Protocol); } - public override void HandleFrame(InboundFrame frame) + public override void HandleFrame(in InboundFrame frame) { - using (Command cmd = _assembler.HandleFrame(frame)) + using (Command cmd = _assembler.HandleFrame(in frame)) { if (cmd != null) { diff --git a/projects/RabbitMQ.Client/client/impl/SessionBase.cs b/projects/RabbitMQ.Client/client/impl/SessionBase.cs index 522238ea74..9a6154f059 100644 --- a/projects/RabbitMQ.Client/client/impl/SessionBase.cs +++ b/projects/RabbitMQ.Client/client/impl/SessionBase.cs @@ -153,7 +153,7 @@ public void Close(ShutdownEventArgs reason, bool notify) } } - public abstract void HandleFrame(InboundFrame frame); + public abstract void HandleFrame(in InboundFrame frame); public void Notify() {