From 4c2cd1841a3859e16edb0928eed5f33f6335b113 Mon Sep 17 00:00:00 2001 From: Erik O'Leary Date: Mon, 21 Aug 2023 16:44:09 -0500 Subject: [PATCH] Remove unnecessary stream; directly use serializetobytes --- .../Communication/ActorMessageBodyJsonConverter.cs | 7 +------ .../ActorMessageBodyJsonSerializationProvider.cs | 14 ++------------ 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs b/src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs index 70bdfe05f..0c77adb10 100644 --- a/src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs +++ b/src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs @@ -36,11 +36,6 @@ public ActorMessageBodyJsonConverter( { this.wrapperMessageType = this.wrappedRequestMessageTypes[0]; } - - // If T is of WrappedMessageBody, then get the 'Value' property. - if (typeof(T).IsAssignableFrom(typeof(WrappedMessageBody))) - { - } } public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) @@ -77,7 +72,7 @@ public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerial // Coerce the type to T; required because WrappedMessageBody inherits from two separate interfaces, which // cannot both be used as generic constraints - return (T)((object)wrapper); + return (T)(object)wrapper; } return JsonSerializer.Deserialize(ref reader, options); diff --git a/src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs b/src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs index ff39848d1..fd35db8e1 100644 --- a/src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs +++ b/src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs @@ -123,12 +123,7 @@ byte[] IActorRequestMessageBodySerializer.Serialize(IActorRequestMessageBody act return null; } - using var stream = new MemoryStream(); - using var writer = new Utf8JsonWriter(stream); - JsonSerializer.Serialize(writer, actorRequestMessageBody, this.serializerOptions); - writer.Flush(); - - return stream.ToArray(); + return JsonSerializer.SerializeToUtf8Bytes(actorRequestMessageBody, this.serializerOptions); } async ValueTask IActorRequestMessageBodySerializer.DeserializeAsync(Stream stream) @@ -154,12 +149,7 @@ byte[] IActorResponseMessageBodySerializer.Serialize(IActorResponseMessageBody a return null; } - using var stream = new MemoryStream(); - using var writer = new Utf8JsonWriter(stream); - JsonSerializer.Serialize(writer, actorResponseMessageBody, this.serializerOptions); - writer.Flush(); - - return stream.ToArray(); + return JsonSerializer.SerializeToUtf8Bytes(actorResponseMessageBody, this.serializerOptions); } async ValueTask IActorResponseMessageBodySerializer.DeserializeAsync(Stream messageBody)