Skip to content

Commit 4d8fff1

Browse files
committed
No need to copy data around here. Add a comment explaining the purpose of this method. Copied from the Java client.
1 parent 8f555c7 commit 4d8fff1

File tree

1 file changed

+6
-4
lines changed
  • projects/RabbitMQ.Client/client/impl

1 file changed

+6
-4
lines changed

projects/RabbitMQ.Client/client/impl/Frame.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,22 +221,24 @@ private InboundFrame(FrameType type, int channel, ReadOnlyMemory<byte> payload,
221221

222222
private static void ProcessProtocolHeader(ReadOnlySequence<byte> buffer)
223223
{
224+
// Probably an AMQP.... header indicating a version mismatch.
225+
// Otherwise meaningless, so try to read the version and throw an exception, whether we
226+
// read the version correctly or not.
224227
try
225228
{
226229
if (buffer.Length < 8)
227230
{
228231
throw new EndOfStreamException();
229232
}
230233

231-
Span<byte> tempSpan = stackalloc byte[8];
232-
buffer.Slice(0, 8).CopyTo(tempSpan);
234+
var bufferSpan = buffer.First.Span;
233235

234-
if (tempSpan[1] != 'M' || tempSpan[2] != 'Q' || tempSpan[3] != 'P')
236+
if (bufferSpan[1] != 'M' || bufferSpan[2] != 'Q' || bufferSpan[3] != 'P')
235237
{
236238
throw new MalformedFrameException("Invalid AMQP protocol header from server");
237239
}
238240

239-
throw new PacketNotRecognizedException(tempSpan[4], tempSpan[5], tempSpan[6], tempSpan[7]);
241+
throw new PacketNotRecognizedException(bufferSpan[4], bufferSpan[5], bufferSpan[6], bufferSpan[7]);
240242
}
241243
catch (EndOfStreamException)
242244
{

0 commit comments

Comments
 (0)