-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#906 -Added methods in status API supports for saving and reading bin…
…ary data (#1116) * Added methods in status API supports for direct storage and reading of byte arrays #906 Signed-off-by: Divya Perumal <[email protected]> Signed-off-by: Divya Perumal <[email protected]>
- Loading branch information
Showing
12 changed files
with
1,042 additions
and
350 deletions.
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
47 changes: 47 additions & 0 deletions
47
examples/Client/StateManagement/StateStoreBinaryExample.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,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Dapr.Client; | ||
using System.Threading.Tasks; | ||
using System.Threading; | ||
using Google.Protobuf; | ||
|
||
namespace Samples.Client | ||
{ | ||
public class StateStoreBinaryExample : Example | ||
{ | ||
|
||
private static readonly string stateKeyName = "binarydata"; | ||
private static readonly string storeName = "statestore"; | ||
|
||
public override string DisplayName => "Using the State Store with binary data"; | ||
|
||
public override async Task RunAsync(CancellationToken cancellationToken) | ||
{ | ||
using var client = new DaprClientBuilder().Build(); | ||
|
||
var state = "Test Binary Data"; | ||
// convert variable in to byte array | ||
var stateBytes = Encoding.UTF8.GetBytes(state); | ||
await client.SaveByteStateAsync(storeName, stateKeyName, stateBytes.AsMemory(), cancellationToken: cancellationToken); | ||
Console.WriteLine("Saved State!"); | ||
|
||
var responseBytes = await client.GetByteStateAsync(storeName, stateKeyName, cancellationToken: cancellationToken); | ||
var savedState = Encoding.UTF8.GetString(ByteString.CopyFrom(responseBytes.Span).ToByteArray()); | ||
|
||
if (savedState == null) | ||
{ | ||
Console.WriteLine("State not found in store"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"Got State: {savedState}"); | ||
} | ||
|
||
await client.DeleteStateAsync(storeName, stateKeyName, cancellationToken: cancellationToken); | ||
Console.WriteLine("Deleted State!"); | ||
} | ||
|
||
|
||
} | ||
} |
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
Oops, something went wrong.