-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for Dictionary Length API
- Loading branch information
1 parent
c3133d4
commit 9d605f9
Showing
7 changed files
with
193 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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 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
105 changes: 105 additions & 0 deletions
105
src/Momento.Sdk/Responses/CacheDictionaryLengthResponse.cs
This file contains 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,105 @@ | ||
using Momento.Protos.CacheClient; | ||
using Momento.Sdk.Exceptions; | ||
|
||
namespace Momento.Sdk.Responses; | ||
|
||
/// <summary> | ||
/// Parent response type for a cache dictionary length request. The | ||
/// response object is resolved to a type-safe object of one of | ||
/// the following subtypes: | ||
/// <list type="bullet"> | ||
/// <item><description>CacheDictionaryLengthResponse.Hit</description></item> | ||
/// <item><description>CacheDictionaryLengthResponse.Miss</description></item> | ||
/// <item><description>CacheDictionaryLengthResponse.Error</description></item> | ||
/// </list> | ||
/// Pattern matching can be used to operate on the appropriate subtype. | ||
/// For example: | ||
/// <code> | ||
/// if (response is CacheDictionaryLengthResponse.Hit successResponse) | ||
/// { | ||
/// return successResponse.Length; | ||
/// } | ||
/// else if (response is CacheListLengthResponse.Miss missResponse) | ||
/// { | ||
/// // handle missResponse as appropriate | ||
/// } | ||
/// else if (response is CacheListLengthResponse.Error errorResponse) | ||
/// { | ||
/// // handle error as appropriate | ||
/// } | ||
/// else | ||
/// { | ||
/// // handle unexpected response | ||
/// } | ||
/// </code> | ||
/// </summary> | ||
public abstract class CacheDictionaryLengthResponse | ||
{ | ||
/// <include file="../docs.xml" path='docs/class[@name="Hit"]/description/*' /> | ||
public class Hit : CacheDictionaryLengthResponse | ||
{ | ||
/// <summary> | ||
/// The length of the dictionary. If the dictionary is missing or empty, the result is zero. | ||
/// </summary> | ||
public int Length { get; private set; } = 0; | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="response">The cache response.</param> | ||
public Hit(_DictionaryLengthResponse response) | ||
{ | ||
if(response.DictionaryCase == _DictionaryLengthResponse.DictionaryOneofCase.Found) { | ||
Length = checked((int)response.Found.Length); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override string ToString() | ||
{ | ||
return $"{base.ToString()}: Length: {Length}"; | ||
} | ||
} | ||
|
||
/// <include file="../docs.xml" path='docs/class[@name="Miss"]/description/*' /> | ||
public class Miss : CacheDictionaryLengthResponse | ||
{ | ||
|
||
} | ||
|
||
/// <include file="../docs.xml" path='docs/class[@name="Error"]/description/*' /> | ||
public class Error : CacheDictionaryLengthResponse, IError | ||
{ | ||
private readonly SdkException _error; | ||
|
||
/// <include file="../docs.xml" path='docs/class[@name="Error"]/constructor/*' /> | ||
public Error(SdkException error) | ||
{ | ||
_error = error; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public SdkException InnerException | ||
{ | ||
get => _error; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public MomentoErrorCode ErrorCode | ||
{ | ||
get => _error.ErrorCode; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public string Message | ||
{ | ||
get => $"{_error.MessageWrapper}: {_error.Message}"; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override string ToString() | ||
{ | ||
return $"{base.ToString()}: {this.Message}"; | ||
} | ||
} | ||
} |
This file contains 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