-
Notifications
You must be signed in to change notification settings - Fork 583
[TestSuit] Fix CanDoSRANDMEMBERWithCountCommandLC test #1143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ee05fab
Fix CanDoSRANDMEMBERWithCountCommandLC test
prvyk 0619619
Convert test to GarnetClientSession.
prvyk 27be6eb
Go back to lightClient. Add a simple RESP parsing class to verify res…
prvyk 5e187e2
Add some RESP3 types to simple reader.
prvyk 7262757
fmt
prvyk df30b6b
No need for unsafe now.
prvyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Garnet.common.Parsing; | ||
|
||
namespace Garnet.test | ||
{ | ||
public static class TestSimpleReadRESP | ||
{ | ||
public static object[] ReadRESP(byte[] inputArray) | ||
{ | ||
var pos = 0; | ||
var input = Encoding.ASCII.GetString(inputArray); | ||
|
||
return Read(input, ref pos); | ||
} | ||
|
||
public static object[] ReadRESP(string input) | ||
{ | ||
var pos = 0; | ||
return Read(input, ref pos); | ||
} | ||
|
||
static object[] Read(string input, ref int pos) | ||
{ | ||
switch (input[pos]) | ||
{ | ||
case ':': | ||
pos++; | ||
var resultInt = ReadIntegerAsString(input, ref pos); | ||
return [resultInt]; | ||
|
||
case '$': | ||
case '~': | ||
case '%': | ||
pos++; | ||
var resultBulk = ReadStringWithLengthHeader(input, ref pos); | ||
return [resultBulk]; | ||
|
||
case '*': | ||
pos++; | ||
var resultArray = ReadStringArrayWithLengthHeader(input, ref pos); | ||
return resultArray; | ||
|
||
case '+': | ||
pos++; | ||
var resultString = ReadSimpleString(input, ref pos); | ||
return [resultString]; | ||
|
||
case '-': | ||
pos++; | ||
var errorString = ReadErrorAsString(input, ref pos); | ||
return [errorString]; | ||
|
||
case ',': | ||
pos++; | ||
var resultDouble = ReadDoubleAsString(input, ref pos); | ||
return [resultDouble]; | ||
|
||
default: | ||
RespParsingException.Throw($"Unexpected character {input[0]}"); | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
private static object[] ReadStringArrayWithLengthHeader(string input, ref int loc) | ||
{ | ||
var pos = input.IndexOf("\r\n", loc); | ||
if (pos == -1) | ||
RespParsingException.Throw("No newline"); | ||
|
||
var arraylen = int.Parse(input[loc..pos]); | ||
loc = pos + 2; | ||
|
||
if (arraylen < 0) | ||
RespParsingException.ThrowInvalidLength(arraylen); | ||
|
||
List<object> lo = new(arraylen); | ||
for (var i = 0; i < arraylen; i++) | ||
{ | ||
var res = Read(input, ref loc); | ||
lo.AddRange(res); | ||
} | ||
|
||
return [.. lo]; | ||
} | ||
|
||
private static string ReadStringWithLengthHeader(string input, ref int loc) | ||
{ | ||
var pos = input.IndexOf("\r\n", loc); | ||
if (pos == -1) | ||
RespParsingException.Throw("No newline"); | ||
|
||
var len = int.Parse(input[loc..pos]); | ||
if (len < -1) | ||
RespParsingException.ThrowInvalidStringLength(len); | ||
|
||
loc = input.IndexOf("\r\n", pos + 2) + 2; | ||
if (loc < 0) | ||
RespParsingException.Throw("No newline!"); | ||
|
||
if (len == -1) | ||
{ | ||
return null; | ||
} | ||
|
||
if (loc != pos + 2 + len + 2) | ||
RespParsingException.Throw("Invalid length!"); | ||
|
||
return input[(pos + 2)..(pos + 2 + len)]; | ||
} | ||
|
||
private static string ReadErrorAsString(string input, ref int loc) | ||
{ | ||
var pos = input.IndexOf("\r\n", loc); | ||
if (pos == -1) | ||
RespParsingException.Throw("No newline"); | ||
|
||
var ret = input[loc..pos]; | ||
loc = pos + 2; | ||
|
||
return ret; | ||
} | ||
|
||
private static double ReadDoubleAsString(string input, ref int loc) | ||
{ | ||
var pos = input.IndexOf("\r\n", loc); | ||
if (pos == -1) | ||
RespParsingException.Throw("No newline"); | ||
|
||
var ret = double.Parse(input[loc..pos]); | ||
loc = pos + 2; | ||
|
||
return ret; | ||
} | ||
|
||
private static long ReadIntegerAsString(string input, ref int loc) | ||
{ | ||
var pos = input.IndexOf("\r\n", loc); | ||
if (pos == -1) | ||
RespParsingException.Throw("No newline"); | ||
|
||
var ret = long.Parse(input[loc..pos]); | ||
loc = pos + 2; | ||
|
||
return ret; | ||
} | ||
|
||
private static string ReadSimpleString(string input, ref int loc) | ||
{ | ||
var pos = input.IndexOf("\r\n", loc); | ||
if (pos == -1) | ||
RespParsingException.Throw("No newline"); | ||
|
||
var ret = input[loc..pos]; | ||
loc = pos + 2; | ||
|
||
return ret; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.