Skip to content

Commit 4069854

Browse files
Stefán J. Sigurðarsonlukebakken
authored andcommitted
Cleaning up CommandAssembler.
1 parent 025b7e4 commit 4069854

File tree

1 file changed

+32
-37
lines changed

1 file changed

+32
-37
lines changed

projects/client/RabbitMQ.Client/src/client/impl/CommandAssembler.cs

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -77,51 +77,46 @@ public Command HandleFrame(InboundFrame f)
7777
switch (m_state)
7878
{
7979
case AssemblyState.ExpectingMethod:
80+
if (!f.IsMethod())
8081
{
81-
if (!f.IsMethod())
82-
{
83-
throw new UnexpectedFrameException(f);
84-
}
85-
m_method = m_protocol.DecodeMethodFrom(f.Payload.AsMemory(0, f.PayloadSize));
86-
m_state = m_method.HasContent
87-
? AssemblyState.ExpectingContentHeader
88-
: AssemblyState.Complete;
89-
return CompletedCommand();
82+
throw new UnexpectedFrameException(f);
9083
}
84+
m_method = m_protocol.DecodeMethodFrom(f.Payload.AsMemory(0, f.PayloadSize));
85+
m_state = m_method.HasContent ? AssemblyState.ExpectingContentHeader : AssemblyState.Complete;
86+
return CompletedCommand();
9187
case AssemblyState.ExpectingContentHeader:
88+
if (!f.IsHeader())
9289
{
93-
if (!f.IsHeader())
94-
{
95-
throw new UnexpectedFrameException(f);
96-
}
97-
Memory<byte> memory = f.Payload.AsMemory(0, f.PayloadSize);
98-
m_header = m_protocol.DecodeContentHeaderFrom(NetworkOrderDeserializer.ReadUInt16(memory));
99-
ulong totalBodyBytes = m_header.ReadFrom(memory.Slice(2));
100-
if (totalBodyBytes > MaxArrayOfBytesSize)
101-
{
102-
throw new UnexpectedFrameException(f);
103-
}
104-
m_remainingBodyBytes = (int)totalBodyBytes;
105-
m_body = new byte[m_remainingBodyBytes];
106-
m_bodyStream = new MemoryStream(m_body, true);
107-
UpdateContentBodyState();
108-
return CompletedCommand();
90+
throw new UnexpectedFrameException(f);
10991
}
92+
Memory<byte> memory = f.Payload.AsMemory(0, f.PayloadSize);
93+
m_header = m_protocol.DecodeContentHeaderFrom(NetworkOrderDeserializer.ReadUInt16(memory));
94+
ulong totalBodyBytes = m_header.ReadFrom(memory.Slice(2));
95+
if (totalBodyBytes > MaxArrayOfBytesSize)
96+
{
97+
throw new UnexpectedFrameException(f);
98+
}
99+
100+
m_remainingBodyBytes = (int)totalBodyBytes;
101+
m_body = new byte[m_remainingBodyBytes];
102+
m_bodyStream = new MemoryStream(m_body, true);
103+
UpdateContentBodyState();
104+
return CompletedCommand();
110105
case AssemblyState.ExpectingContentBody:
106+
if (!f.IsBody())
111107
{
112-
if (!f.IsBody())
113-
{
114-
throw new UnexpectedFrameException(f);
115-
}
116-
if (f.PayloadSize > m_remainingBodyBytes)
117-
{
118-
throw new MalformedFrameException($"Overlong content body received - {m_remainingBodyBytes} bytes remaining, {f.PayloadSize} bytes received");
119-
}
120-
m_bodyStream.Write(f.Payload, 0, f.PayloadSize);
121-
m_remainingBodyBytes -= f.PayloadSize;
122-
UpdateContentBodyState();
123-
return CompletedCommand();
108+
throw new UnexpectedFrameException(f);
124109
}
110+
111+
if (f.PayloadSize > m_remainingBodyBytes)
112+
{
113+
throw new MalformedFrameException($"Overlong content body received - {m_remainingBodyBytes} bytes remaining, {f.PayloadSize} bytes received");
114+
}
115+
116+
m_bodyStream.Write(f.Payload, 0, f.PayloadSize);
117+
m_remainingBodyBytes -= f.PayloadSize;
118+
UpdateContentBodyState();
119+
return CompletedCommand();
125120
case AssemblyState.Complete:
126121
default:
127122
return null;

0 commit comments

Comments
 (0)