Skip to content

Commit 3b497f9

Browse files
committed
Move functions to file where they're used.
1 parent 0d9b2a9 commit 3b497f9

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

@@ -2966,6 +2967,76 @@ private static bool TryParseInlineCommandArguments(bool writeErrorOnFailure, out
29662967
return false;
29672968
}
29682969

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

libs/server/Resp/RespServerSession.cs

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

1122-
ReadOnlySpan<byte> GetCommand(out bool success)
1123-
{
1124-
var ptr = recvBufferPtr + readHead;
1125-
var end = recvBufferPtr + bytesRead;
1126-
1127-
// Try the command length
1128-
if (!RespReadUtils.TryReadUnsignedLengthHeader(out int length, ref ptr, end))
1129-
{
1130-
success = false;
1131-
return default;
1132-
}
1133-
1134-
readHead = (int)(ptr - recvBufferPtr);
1135-
1136-
// Try to read the command value
1137-
ptr += length;
1138-
if (ptr + 2 > end)
1139-
{
1140-
success = false;
1141-
return default;
1142-
}
1143-
1144-
if (*(ushort*)ptr != MemoryMarshal.Read<ushort>("\r\n"u8))
1145-
{
1146-
RespParsingException.ThrowUnexpectedToken(*ptr);
1147-
}
1148-
1149-
var result = new ReadOnlySpan<byte>(recvBufferPtr + readHead, length);
1150-
readHead += length + 2;
1151-
success = true;
1152-
1153-
return result;
1154-
}
1155-
1156-
ReadOnlySpan<byte> GetUpperCaseCommand(out bool success)
1157-
{
1158-
var ptr = recvBufferPtr + readHead;
1159-
var end = recvBufferPtr + bytesRead;
1160-
1161-
// Try the command length
1162-
if (!RespReadUtils.TryReadUnsignedLengthHeader(out int length, ref ptr, end))
1163-
{
1164-
success = false;
1165-
return default;
1166-
}
1167-
1168-
readHead = (int)(ptr - recvBufferPtr);
1169-
1170-
// Try to read the command value
1171-
ptr += length;
1172-
if (ptr + 2 > end)
1173-
{
1174-
success = false;
1175-
return default;
1176-
}
1177-
1178-
if (*(ushort*)ptr != MemoryMarshal.Read<ushort>("\r\n"u8))
1179-
{
1180-
RespParsingException.ThrowUnexpectedToken(*ptr);
1181-
}
1182-
1183-
var result = new Span<byte>(recvBufferPtr + readHead, length);
1184-
readHead += length + 2;
1185-
success = true;
1186-
1187-
AsciiUtils.ToUpperInPlace(result);
1188-
return result;
1189-
}
1190-
11911122
/// <summary>
11921123
/// Attempt to kill this session.
11931124
///

0 commit comments

Comments
 (0)