Skip to content
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

Query: Adds new system strings in JsonBinaryEncoding, replacing 1-byte user strings #3400

Merged
merged 3 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ private static class FirstValueOffsets
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,

// Encoded 1-byte system string (32 values)
// Encoded 1-byte system string (64 values)
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,

// Encoded 1-byte user string (32 values)
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ public static class NodeTypes
Number, Number, Number, Number, Number, Number, Number, Number,
Number, Number, Number, Number, Number, Number, Number, Number,

// Encoded 1-byte system string (32 values)
// Encoded 1-byte system string (64 values)
String, String, String, String, String, String, String, String,
String, String, String, String, String, String, String, String,
String, String, String, String, String, String, String, String,
String, String, String, String, String, String, String, String,

// Encoded 1-byte user string (32 values)
String, String, String, String, String, String, String, String,
String, String, String, String, String, String, String, String,
String, String, String, String, String, String, String, String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private static class StringLengths
NotStr, NotStr, NotStr, NotStr, NotStr, NotStr, NotStr, NotStr,
NotStr, NotStr, NotStr, NotStr, NotStr, NotStr, NotStr, NotStr,

// Encoded 1-byte system string (32 values)
// Encoded 1-byte system string (64 values)
SystemStrings.Strings[0].Utf8String.Length, SystemStrings.Strings[1].Utf8String.Length,
SystemStrings.Strings[2].Utf8String.Length, SystemStrings.Strings[3].Utf8String.Length,
SystemStrings.Strings[4].Utf8String.Length, SystemStrings.Strings[5].Utf8String.Length,
Expand All @@ -54,12 +54,22 @@ private static class StringLengths
SystemStrings.Strings[26].Utf8String.Length, SystemStrings.Strings[27].Utf8String.Length,
SystemStrings.Strings[28].Utf8String.Length, SystemStrings.Strings[29].Utf8String.Length,
SystemStrings.Strings[30].Utf8String.Length, SystemStrings.Strings[31].Utf8String.Length,

// Encoded 1-byte user string (32 values)
UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1,
UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1,
UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1,
UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1, UsrStr1,
SystemStrings.Strings[32].Utf8String.Length, SystemStrings.Strings[33].Utf8String.Length,
SystemStrings.Strings[34].Utf8String.Length, SystemStrings.Strings[35].Utf8String.Length,
SystemStrings.Strings[36].Utf8String.Length, SystemStrings.Strings[37].Utf8String.Length,
SystemStrings.Strings[38].Utf8String.Length, SystemStrings.Strings[39].Utf8String.Length,
SystemStrings.Strings[40].Utf8String.Length, SystemStrings.Strings[41].Utf8String.Length,
SystemStrings.Strings[42].Utf8String.Length, SystemStrings.Strings[43].Utf8String.Length,
SystemStrings.Strings[44].Utf8String.Length, SystemStrings.Strings[45].Utf8String.Length,
SystemStrings.Strings[46].Utf8String.Length, SystemStrings.Strings[47].Utf8String.Length,
SystemStrings.Strings[48].Utf8String.Length, SystemStrings.Strings[49].Utf8String.Length,
SystemStrings.Strings[50].Utf8String.Length, SystemStrings.Strings[51].Utf8String.Length,
SystemStrings.Strings[52].Utf8String.Length, SystemStrings.Strings[53].Utf8String.Length,
SystemStrings.Strings[54].Utf8String.Length, SystemStrings.Strings[55].Utf8String.Length,
SystemStrings.Strings[56].Utf8String.Length, SystemStrings.Strings[57].Utf8String.Length,
SystemStrings.Strings[58].Utf8String.Length, SystemStrings.Strings[59].Utf8String.Length,
SystemStrings.Strings[60].Utf8String.Length, SystemStrings.Strings[61].Utf8String.Length,
SystemStrings.Strings[62].Utf8String.Length, SystemStrings.Strings[63].Utf8String.Length,

// Encoded 2-byte user string (8 values)
UsrStr2, UsrStr2, UsrStr2, UsrStr2, UsrStr2, UsrStr2, UsrStr2, UsrStr2,
Expand Down
29 changes: 6 additions & 23 deletions Microsoft.Azure.Cosmos/src/Json/JsonBinaryEncoding.Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ internal static partial class JsonBinaryEncoding
false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false,

// Encoded 0-byte system string (32 values)
// Encoded 0-byte system string (64 values)
true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true,

// Encoded true-byte user string (32 values)
true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true,
Expand Down Expand Up @@ -386,29 +384,14 @@ private static bool TryGetUserStringId(ReadOnlySpan<byte> stringToken, out int u
return false;
}

if (JsonBinaryEncoding.TypeMarker.IsOneByteEncodedUserString(typeMarker))
// JsonBinaryEncoding.TypeMarker.IsTwoByteEncodedUserString(typeMarker) must be true
if (stringToken.Length < 2)
{
if (stringToken.Length < 1)
{
userStringId = default;
return false;
}

userStringId = typeMarker - JsonBinaryEncoding.TypeMarker.UserString1ByteLengthMin;
userStringId = default;
return false;
}
else //// JsonBinaryEncoding.TypeMarker.IsTwoByteEncodedUserString(typeMarker)
{
if (stringToken.Length < 2)
{
userStringId = default;
return false;
}

const byte OneByteCount = JsonBinaryEncoding.TypeMarker.UserString1ByteLengthMax - JsonBinaryEncoding.TypeMarker.UserString1ByteLengthMin;
userStringId = OneByteCount
+ stringToken[1]
+ ((stringToken[0] - JsonBinaryEncoding.TypeMarker.UserString2ByteLengthMin) * 0xFF);
}
userStringId = stringToken[1] + ((stringToken[0] - JsonBinaryEncoding.TypeMarker.UserString2ByteLengthMin) * 0xFF);

return true;
}
Expand Down
Loading