11// Copyright (c) Microsoft Corporation.
22// Licensed under the MIT License.
33
4+ using System . Diagnostics . CodeAnalysis ;
45using System . Text ;
56
67namespace Microsoft . DurableTask . Converters ;
@@ -20,25 +21,39 @@ namespace Microsoft.DurableTask.Converters;
2021public sealed class LargePayloadDataConverter (
2122 DataConverter innerConverter ,
2223 IPayloadStore payloadStore ,
23- LargePayloadStorageOptions largePayloadStorageOptions
24- ) : DataConverter
24+ LargePayloadStorageOptions largePayloadStorageOptions ) : DataConverter
2525{
26-
2726 readonly DataConverter innerConverter = innerConverter ?? throw new ArgumentNullException ( nameof ( innerConverter ) ) ;
2827 readonly IPayloadStore payLoadStore = payloadStore ?? throw new ArgumentNullException ( nameof ( payloadStore ) ) ;
2928 readonly LargePayloadStorageOptions largePayloadStorageOptions = largePayloadStorageOptions ?? throw new ArgumentNullException ( nameof ( largePayloadStorageOptions ) ) ;
29+
3030 // Use UTF-8 without a BOM (encoderShouldEmitUTF8Identifier=false). JSON in UTF-8 should not include a
3131 // byte order mark per RFC 8259, and omitting it avoids hidden extra bytes that could skew the
3232 // externalization threshold calculation and prevents interop issues with strict JSON parsers.
3333 // A few legacy tools rely on a BOM for encoding detection, but modern JSON tooling assumes BOM-less UTF-8.
3434 readonly Encoding utf8 = new UTF8Encoding ( false ) ;
3535
36+ /// <inheritdoc/>
37+ [ return : NotNullIfNotNull ( "value" ) ]
38+ public override string ? Serialize ( object ? value )
39+ {
40+ throw new NotImplementedException ( ) ;
41+ }
42+
43+ /// <inheritdoc/>
44+ [ return : NotNullIfNotNull ( "data" ) ]
45+ public override object ? Deserialize ( string ? data , Type targetType )
46+ {
47+ throw new NotImplementedException ( ) ;
48+ }
49+
3650 /// <summary>
3751 /// Serializes the value to a JSON string and uploads it to the external payload store if it exceeds the configured threshold.
3852 /// </summary>
3953 /// <param name="value">The value to serialize.</param>
54+ /// <param name="cancellationToken">Cancellation token.</param>
4055 /// <returns>The serialized value or the token if externalized.</returns>
41- public override string ? Serialize ( object ? value )
56+ public override async ValueTask < string ? > SerializeAsync ( object ? value , CancellationToken cancellationToken = default )
4257 {
4358 string ? json = this . innerConverter . Serialize ( value ) ;
4459
@@ -55,17 +70,20 @@ LargePayloadStorageOptions largePayloadStorageOptions
5570
5671 // Upload synchronously in this context by blocking on async. SDK call sites already run on threadpool.
5772 byte [ ] bytes = this . utf8 . GetBytes ( json ) ;
58- string token = this . payLoadStore . UploadAsync ( bytes , CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) ;
59- return token ;
73+ return await this . payLoadStore . UploadAsync ( bytes , cancellationToken ) ;
6074 }
6175
6276 /// <summary>
6377 /// Deserializes the JSON string or resolves the token to the original value.
6478 /// </summary>
6579 /// <param name="data">The JSON string or token.</param>
6680 /// <param name="targetType">The type to deserialize to.</param>
81+ /// <param name="cancellationToken">Cancellation token.</param>
6782 /// <returns>The deserialized value.</returns>
68- public override object ? Deserialize ( string ? data , Type targetType )
83+ public override async ValueTask < object ? > DeserializeAsync (
84+ string ? data ,
85+ Type targetType ,
86+ CancellationToken cancellationToken = default )
6987 {
7088 if ( data is null )
7189 {
@@ -75,7 +93,7 @@ LargePayloadStorageOptions largePayloadStorageOptions
7593 string toDeserialize = data ;
7694 if ( this . payLoadStore . IsKnownPayloadToken ( data ) )
7795 {
78- toDeserialize = this . payLoadStore . DownloadAsync ( data , CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) ;
96+ toDeserialize = await this . payLoadStore . DownloadAsync ( data , CancellationToken . None ) ;
7997 }
8098
8199 return this . innerConverter . Deserialize ( StripArrayCharacters ( toDeserialize ) , targetType ) ;
@@ -92,5 +110,3 @@ LargePayloadStorageOptions largePayloadStorageOptions
92110 return input ;
93111 }
94112}
95-
96-
0 commit comments