Skip to content

Commit 52ec85c

Browse files
committed
more
1 parent 281fed2 commit 52ec85c

File tree

6 files changed

+65
-10
lines changed

6 files changed

+65
-10
lines changed

src/Client/Core/OrchestrationMetadata.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ public OrchestrationMetadata(string name, string instanceId)
8080
/// <value>The serialized custom status or <c>null</c>.</value>
8181
public string? SerializedCustomStatus { get; init; }
8282

83+
/// <summary>
84+
/// Gets a value indicating whether large payload support is enabled.
85+
/// </summary>
86+
/// <value><c>true</c> if large payload support is enabled; <c>false</c> otherwise.</value>
87+
public bool EnableLargePayloadSupport { get; init; }
88+
8389
/// <summary>
8490
/// Gets the tags associated with the orchestration instance.
8591
/// </summary>
@@ -141,6 +147,7 @@ public OrchestrationMetadata(string name, string instanceId)
141147
"that are fetched with the option to include input data.");
142148
}
143149

150+
Check.ThrowIfLargePayloadEnabled(this.EnableLargePayloadSupport, nameof(this.ReadInputAs));
144151
return this.DataConverter.Deserialize<T>(this.SerializedInput);
145152
}
146153

@@ -167,6 +174,7 @@ public OrchestrationMetadata(string name, string instanceId)
167174
"that are fetched with the option to include output data.");
168175
}
169176

177+
Check.ThrowIfLargePayloadEnabled(this.EnableLargePayloadSupport, nameof(this.ReadOutputAs));
170178
return this.DataConverter.Deserialize<T>(this.SerializedOutput);
171179
}
172180

@@ -193,6 +201,7 @@ public OrchestrationMetadata(string name, string instanceId)
193201
+ " objects that are fetched with the option to include input and output data.");
194202
}
195203

204+
Check.ThrowIfLargePayloadEnabled(this.EnableLargePayloadSupport, nameof(this.ReadCustomStatusAs));
196205
return this.DataConverter.Deserialize<T>(this.SerializedCustomStatus);
197206
}
198207

@@ -220,7 +229,12 @@ public OrchestrationMetadata(string name, string instanceId)
220229
"that are fetched with the option to include input data.");
221230
}
222231

223-
return await this.DataConverter.DeserializeAsync<T>(this.SerializedInput, cancellationToken);
232+
if (this.EnableLargePayloadSupport)
233+
{
234+
return await this.DataConverter.DeserializeAsync<T>(this.SerializedInput, cancellationToken);
235+
}
236+
237+
return this.DataConverter.Deserialize<T>(this.SerializedInput);
224238
}
225239

226240
/// <summary>
@@ -247,7 +261,12 @@ public OrchestrationMetadata(string name, string instanceId)
247261
"that are fetched with the option to include output data.");
248262
}
249263

250-
return await this.DataConverter.DeserializeAsync<T>(this.SerializedOutput, cancellationToken);
264+
if (this.EnableLargePayloadSupport)
265+
{
266+
return await this.DataConverter.DeserializeAsync<T>(this.SerializedOutput, cancellationToken);
267+
}
268+
269+
return this.DataConverter.Deserialize<T>(this.SerializedOutput);
251270
}
252271

253272
/// <summary>
@@ -274,6 +293,11 @@ public OrchestrationMetadata(string name, string instanceId)
274293
" objects that are fetched with the option to include input and output data.");
275294
}
276295

296+
if (this.EnableLargePayloadSupport)
297+
{
298+
return await this.DataConverter.DeserializeAsync<T>(this.SerializedCustomStatus, cancellationToken);
299+
}
300+
277301
return await this.DataConverter.DeserializeAsync<T>(this.SerializedCustomStatus, cancellationToken);
278302
}
279303

src/Client/Core/SerializedData.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public sealed class SerializedData(string data, DataConverter? converter = null)
2020
/// </summary>
2121
public string Value { get; } = Check.NotNull(data);
2222

23+
/// <summary>
24+
/// Gets a value indicating whether large payload support is enabled.
25+
/// </summary>
26+
public bool EnableLargePayloadSupport { get; init; }
27+
2328
/// <summary>
2429
/// Gets the data converter.
2530
/// </summary>
@@ -30,7 +35,11 @@ public sealed class SerializedData(string data, DataConverter? converter = null)
3035
/// </summary>
3136
/// <typeparam name="T">The type to deserialize into.</typeparam>
3237
/// <returns>The deserialized type.</returns>
33-
public T ReadAs<T>() => this.Converter.Deserialize<T>(this.Value);
38+
public T ReadAs<T>()
39+
{
40+
Check.ThrowIfLargePayloadEnabled(this.EnableLargePayloadSupport, nameof(this.ReadAs));
41+
return this.Converter.Deserialize<T>(this.Value);
42+
}
3443

3544
/// <summary>
3645
/// Deserializes the data into <typeparamref name="T"/>.
@@ -44,21 +53,29 @@ public sealed class SerializedData(string data, DataConverter? converter = null)
4453
/// </summary>
4554
/// <param name="data">The data to serialize.</param>
4655
/// <param name="converter">The data converter.</param>
56+
/// <param name="enableLargePayloadSupport">Whether to use async serialization for large payloads.</param>
4757
/// <returns>Serialized data.</returns>
48-
internal static SerializedData Create(object data, DataConverter? converter = null)
58+
internal static SerializedData Create(object data, DataConverter? converter = null, bool enableLargePayloadSupport = false)
4959
{
5060
converter ??= JsonDataConverter.Default;
51-
return new SerializedData(converter.Serialize(data), converter);
61+
return new SerializedData(converter.Serialize(data), converter)
62+
{
63+
EnableLargePayloadSupport = enableLargePayloadSupport,
64+
};
5265
}
5366

5467
/// <summary>
5568
/// Creates a new instance of <see cref="SerializedData"/> from the specified data.
5669
/// </summary>
5770
/// <param name="data">The data to serialize.</param>
5871
/// <param name="converter">The data converter.</param>
72+
/// <param name="enableLargePayloadSupport">Whether to use async serialization for large payloads.</param>
5973
/// <returns>Serialized data.</returns>
60-
internal static async Task<SerializedData> CreateAsync(object data, DataConverter converter)
74+
internal static async Task<SerializedData> CreateAsync(object data, DataConverter converter, bool enableLargePayloadSupport = false)
6175
{
62-
return new SerializedData(await converter.SerializeAsync(data), converter);
76+
return new SerializedData(await converter.SerializeAsync(data), converter)
77+
{
78+
EnableLargePayloadSupport = enableLargePayloadSupport,
79+
};
6380
}
6481
}

src/Client/Grpc/GrpcDurableEntityClient.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ class GrpcDurableEntityClient : DurableEntityClient
3030
/// <param name="logger">The logger for logging client requests.</param>
3131
/// <param name="enableLargePayloadSupport">Whether to use async serialization for large payloads.</param>
3232
public GrpcDurableEntityClient(
33-
string name, DataConverter dataConverter, TaskHubSidecarServiceClient sidecarClient, ILogger logger, bool enableLargePayloadSupport = false)
33+
string name,
34+
DataConverter dataConverter,
35+
TaskHubSidecarServiceClient sidecarClient,
36+
ILogger logger,
37+
bool enableLargePayloadSupport = false)
3438
: base(name)
3539
{
3640
this.dataConverter = dataConverter;
@@ -305,7 +309,10 @@ EntityMetadata ToEntityMetadata(P.EntityMetadata metadata, bool includeState)
305309
EntityInstanceId entityId = new(coreEntityId.Name, coreEntityId.Key);
306310
bool hasState = metadata.SerializedState != null;
307311

308-
SerializedData? data = (includeState && hasState) ? new(metadata.SerializedState!, this.dataConverter) : null;
312+
SerializedData? data = (includeState && hasState)
313+
? new SerializedData(metadata.SerializedState!, this.dataConverter)
314+
{ EnableLargePayloadSupport = this.enableLargePayloadSupport }
315+
: null;
309316
return new EntityMetadata(entityId, data)
310317
{
311318
LastModifiedTime = metadata.LastModifiedTime.ToDateTimeOffset(),

src/Client/Grpc/GrpcDurableTaskClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ OrchestrationMetadata CreateMetadata(P.OrchestrationState state, bool includeInp
521521
SerializedCustomStatus = state.CustomStatus,
522522
FailureDetails = state.FailureDetails.ToTaskFailureDetails(),
523523
DataConverter = includeInputsAndOutputs ? this.DataConverter : null,
524+
EnableLargePayloadSupport = this.SupportsAsyncSerialization,
524525
Tags = new Dictionary<string, string>(state.Tags),
525526
};
526527

src/Client/OrchestrationServiceClientShim/ShimDurableEntityClient.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,12 @@ EntityMetadata<T> ConvertSync<T>(EntityBackendQueries.EntityMetadata metadata)
216216

217217
EntityMetadata Convert(EntityBackendQueries.EntityMetadata metadata)
218218
{
219-
SerializedData? data = metadata.SerializedState is null ? null : new(metadata.SerializedState, this.Converter);
219+
SerializedData? data = metadata.SerializedState is null
220+
? null
221+
: new SerializedData(metadata.SerializedState, this.Converter)
222+
{
223+
EnableLargePayloadSupport = this.SupportsAsyncSerialization,
224+
};
220225
return new(new EntityInstanceId(metadata.EntityId.Name, metadata.EntityId.Key), data)
221226
{
222227
LastModifiedTime = metadata.LastModifiedTime,

src/Client/OrchestrationServiceClientShim/ShimDurableTaskClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ public override async Task<string> RestartAsync(
336336
SerializedOutput = state.Output,
337337
SerializedCustomStatus = state.Status,
338338
FailureDetails = state.FailureDetails?.ConvertFromCore(),
339+
EnableLargePayloadSupport = this.SupportsAsyncSerialization,
339340
};
340341
}
341342

0 commit comments

Comments
 (0)