Skip to content

Commit d30d48c

Browse files
committed
Move functions to file where they're used.
1 parent db28a27 commit d30d48c

File tree

2 files changed

+71
-69
lines changed

2 files changed

+71
-69
lines changed

libs/server/Resp/Parser/RespCommand.cs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Runtime.InteropServices;
99
using System.Text;
1010
using Garnet.common;
11+
using Garnet.common.Parsing;
1112
using Microsoft.Extensions.Logging;
1213
using Tsavorite.core;
1314

@@ -2972,6 +2973,76 @@ private static bool TryParseInlineCommandArguments(bool writeErrorOnFailure, out
29722973
return false;
29732974
}
29742975

2976+
2977+
ReadOnlySpan<byte> GetCommand(out bool success)
2978+
{
2979+
var ptr = recvBufferPtr + readHead;
2980+
var end = recvBufferPtr + bytesRead;
2981+
2982+
// Try the command length
2983+
if (!RespReadUtils.TryReadUnsignedLengthHeader(out int length, ref ptr, end))
2984+
{
2985+
success = false;
2986+
return default;
2987+
}
2988+
2989+
readHead = (int)(ptr - recvBufferPtr);
2990+
2991+
// Try to read the command value
2992+
ptr += length;
2993+
if (ptr + 2 > end)
2994+
{
2995+
success = false;
2996+
return default;
2997+
}
2998+
2999+
if (*(ushort*)ptr != CrLf)
3000+
{
3001+
RespParsingException.ThrowUnexpectedToken(*ptr);
3002+
}
3003+
3004+
var result = new ReadOnlySpan<byte>(recvBufferPtr + readHead, length);
3005+
readHead += length + 2;
3006+
success = true;
3007+
3008+
return result;
3009+
}
3010+
3011+
ReadOnlySpan<byte> GetUpperCaseCommand(out bool success)
3012+
{
3013+
var ptr = recvBufferPtr + readHead;
3014+
var end = recvBufferPtr + bytesRead;
3015+
3016+
// Try the command length
3017+
if (!RespReadUtils.TryReadUnsignedLengthHeader(out int length, ref ptr, end))
3018+
{
3019+
success = false;
3020+
return default;
3021+
}
3022+
3023+
readHead = (int)(ptr - recvBufferPtr);
3024+
3025+
// Try to read the command value
3026+
ptr += length;
3027+
if (ptr + 2 > end)
3028+
{
3029+
success = false;
3030+
return default;
3031+
}
3032+
3033+
if (*(ushort*)ptr != CrLf)
3034+
{
3035+
RespParsingException.ThrowUnexpectedToken(*ptr);
3036+
}
3037+
3038+
var result = new Span<byte>(recvBufferPtr + readHead, length);
3039+
readHead += length + 2;
3040+
success = true;
3041+
3042+
AsciiUtils.ToUpperInPlace(result);
3043+
return result;
3044+
}
3045+
29753046
[MethodImpl(MethodImplOptions.NoInlining)]
29763047
private void HandleAofCommitMode(RespCommand cmd)
29773048
{

libs/server/Resp/RespServerSession.cs

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,75 +1133,6 @@ private bool IsCommandArityValid(string cmdName, int arity, int count)
11331133
return true;
11341134
}
11351135

1136-
ReadOnlySpan<byte> GetCommand(out bool success)
1137-
{
1138-
var ptr = recvBufferPtr + readHead;
1139-
var end = recvBufferPtr + bytesRead;
1140-
1141-
// Try the command length
1142-
if (!RespReadUtils.TryReadUnsignedLengthHeader(out int length, ref ptr, end))
1143-
{
1144-
success = false;
1145-
return default;
1146-
}
1147-
1148-
readHead = (int)(ptr - recvBufferPtr);
1149-
1150-
// Try to read the command value
1151-
ptr += length;
1152-
if (ptr + 2 > end)
1153-
{
1154-
success = false;
1155-
return default;
1156-
}
1157-
1158-
if (*(ushort*)ptr != MemoryMarshal.Read<ushort>("\r\n"u8))
1159-
{
1160-
RespParsingException.ThrowUnexpectedToken(*ptr);
1161-
}
1162-
1163-
var result = new ReadOnlySpan<byte>(recvBufferPtr + readHead, length);
1164-
readHead += length + 2;
1165-
success = true;
1166-
1167-
return result;
1168-
}
1169-
1170-
ReadOnlySpan<byte> GetUpperCaseCommand(out bool success)
1171-
{
1172-
var ptr = recvBufferPtr + readHead;
1173-
var end = recvBufferPtr + bytesRead;
1174-
1175-
// Try the command length
1176-
if (!RespReadUtils.TryReadUnsignedLengthHeader(out int length, ref ptr, end))
1177-
{
1178-
success = false;
1179-
return default;
1180-
}
1181-
1182-
readHead = (int)(ptr - recvBufferPtr);
1183-
1184-
// Try to read the command value
1185-
ptr += length;
1186-
if (ptr + 2 > end)
1187-
{
1188-
success = false;
1189-
return default;
1190-
}
1191-
1192-
if (*(ushort*)ptr != MemoryMarshal.Read<ushort>("\r\n"u8))
1193-
{
1194-
RespParsingException.ThrowUnexpectedToken(*ptr);
1195-
}
1196-
1197-
var result = new Span<byte>(recvBufferPtr + readHead, length);
1198-
readHead += length + 2;
1199-
success = true;
1200-
1201-
AsciiUtils.ToUpperInPlace(result);
1202-
return result;
1203-
}
1204-
12051136
/// <summary>
12061137
/// Attempt to kill this session.
12071138
///

0 commit comments

Comments
 (0)