Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof-of-concept serialization of advanced JSON types, records #1073

Merged
merged 5 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/Dapr.Actors/Client/ActorProxyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System;
using System.Net.Http;
using Dapr.Actors.Builder;
using Dapr.Actors.Communication;
using Dapr.Actors.Communication.Client;

/// <summary>
Expand Down Expand Up @@ -79,7 +80,15 @@
options ??= this.DefaultOptions;

var daprInteractor = new DaprHttpInteractor(this.handler, options.HttpEndpoint, options.DaprApiToken, options.RequestTimeout);
var remotingClient = new ActorRemotingClient(daprInteractor);

// provide a serializer if 'useJsonSerialization' is true and no serialization provider is provided.
IActorMessageBodySerializationProvider serializationProvider = null;
if (options.UseJsonSerialization)
{
serializationProvider = new ActorMessageBodyJsonSerializationProvider(options.JsonSerializerOptions);

Check warning on line 88 in src/Dapr.Actors/Client/ActorProxyFactory.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Client/ActorProxyFactory.cs#L88

Added line #L88 was not covered by tests
}

var remotingClient = new ActorRemotingClient(daprInteractor, serializationProvider);
var proxyGenerator = ActorCodeBuilder.GetOrCreateProxyGenerator(actorInterfaceType);
var actorProxy = proxyGenerator.CreateActorProxy();
actorProxy.Initialize(remotingClient, actorId, actorType, options);
Expand Down
5 changes: 5 additions & 0 deletions src/Dapr.Actors/Client/ActorProxyOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,10 @@
/// The timeout allowed for an actor request. Can be set to System.Threading.Timeout.InfiniteTimeSpan to disable any timeouts.
/// </summary>
public TimeSpan? RequestTimeout { get; set; } = null;

/// <summary>
/// Enable JSON serialization for actor proxy message serialization in both remoting and non-remoting invocations.
/// </summary>
public bool UseJsonSerialization { get; set; }

Check warning on line 69 in src/Dapr.Actors/Client/ActorProxyOptions.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Client/ActorProxyOptions.cs#L69

Added line #L69 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using System.Xml;

/// <summary>
Expand Down Expand Up @@ -185,21 +186,21 @@
return stream.ToArray();
}

IActorRequestMessageBody IActorRequestMessageBodySerializer.Deserialize(Stream stream)
ValueTask<IActorRequestMessageBody> IActorRequestMessageBodySerializer.DeserializeAsync(Stream stream)
{
if (stream == null)
{
return null;
return default;

Check warning on line 193 in src/Dapr.Actors/Communication/ActorMessageBodyDataContractSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyDataContractSerializationProvider.cs#L193

Added line #L193 was not covered by tests
}

if (stream.Length == 0)
{
return null;
return default;

Check warning on line 198 in src/Dapr.Actors/Communication/ActorMessageBodyDataContractSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyDataContractSerializationProvider.cs#L198

Added line #L198 was not covered by tests
}

stream.Position = 0;
using var reader = this.CreateXmlDictionaryReader(stream);
return (TRequest)this.serializer.ReadObject(reader);
return new ValueTask<IActorRequestMessageBody>((TRequest)this.serializer.ReadObject(reader));

Check warning on line 203 in src/Dapr.Actors/Communication/ActorMessageBodyDataContractSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyDataContractSerializationProvider.cs#L203

Added line #L203 was not covered by tests
}

byte[] IActorResponseMessageBodySerializer.Serialize(IActorResponseMessageBody actorResponseMessageBody)
Expand All @@ -217,11 +218,11 @@
return stream.ToArray();
}

IActorResponseMessageBody IActorResponseMessageBodySerializer.Deserialize(Stream messageBody)
ValueTask<IActorResponseMessageBody> IActorResponseMessageBodySerializer.DeserializeAsync(Stream messageBody)
{
if (messageBody == null)
{
return null;
return default;

Check warning on line 225 in src/Dapr.Actors/Communication/ActorMessageBodyDataContractSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyDataContractSerializationProvider.cs#L225

Added line #L225 was not covered by tests
}

// TODO check performance
Expand All @@ -231,11 +232,11 @@

if (stream.Capacity == 0)
{
return null;
return default;

Check warning on line 235 in src/Dapr.Actors/Communication/ActorMessageBodyDataContractSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyDataContractSerializationProvider.cs#L235

Added line #L235 was not covered by tests
}

using var reader = this.CreateXmlDictionaryReader(stream);
return (TResponse)this.serializer.ReadObject(reader);
return new ValueTask<IActorResponseMessageBody>((TResponse)this.serializer.ReadObject(reader));

Check warning on line 239 in src/Dapr.Actors/Communication/ActorMessageBodyDataContractSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyDataContractSerializationProvider.cs#L239

Added line #L239 was not covered by tests
}

/// <summary>
Expand Down
95 changes: 95 additions & 0 deletions src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// ------------------------------------------------------------------------
// Copyright 2021 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Dapr.Actors.Communication
{
internal class ActorMessageBodyJsonConverter<T> : JsonConverter<T>
{
private readonly List<Type> methodRequestParameterTypes;
private readonly List<Type> wrappedRequestMessageTypes;
private readonly Type wrapperMessageType;

public ActorMessageBodyJsonConverter(
List<Type> methodRequestParameterTypes,
List<Type> wrappedRequestMessageTypes = null
)

Check warning on line 30 in src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs#L27-L30

Added lines #L27 - L30 were not covered by tests
onionhammer marked this conversation as resolved.
Show resolved Hide resolved
{
this.methodRequestParameterTypes = methodRequestParameterTypes;
this.wrappedRequestMessageTypes = wrappedRequestMessageTypes;

Check warning on line 33 in src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs#L32-L33

Added lines #L32 - L33 were not covered by tests

if (this.wrappedRequestMessageTypes != null && this.wrappedRequestMessageTypes.Count == 1)
{
this.wrapperMessageType = this.wrappedRequestMessageTypes[0];

Check warning on line 37 in src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs#L37

Added line #L37 was not covered by tests
}
}

Check warning on line 39 in src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs#L39

Added line #L39 was not covered by tests

public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
// Ensure start-of-object, then advance
if (reader.TokenType != JsonTokenType.StartObject) throw new JsonException();
reader.Read();

Check warning on line 45 in src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs#L45

Added line #L45 was not covered by tests

// Ensure property name, then advance
if (reader.TokenType != JsonTokenType.PropertyName || reader.GetString() != "value") throw new JsonException();
reader.Read();

Check warning on line 49 in src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs#L49

Added line #L49 was not covered by tests

// If the value is null, return null.
if (reader.TokenType == JsonTokenType.Null)
{
// Read the end object token.
reader.Read();
return default;

Check warning on line 56 in src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs#L55-L56

Added lines #L55 - L56 were not covered by tests
}

// If the value is an object, deserialize it to wrapper message type
if (this.wrapperMessageType != null)
{
var value = JsonSerializer.Deserialize(ref reader, this.wrapperMessageType, options);

Check warning on line 62 in src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs#L62

Added line #L62 was not covered by tests

// Construct a new WrappedMessageBody with the deserialized value.
var wrapper = new WrappedMessageBody()
{
Value = value,
};

Check warning on line 68 in src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs#L65-L68

Added lines #L65 - L68 were not covered by tests

// Read the end object token.
reader.Read();

Check warning on line 71 in src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs#L71

Added line #L71 was not covered by tests

// 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;

Check warning on line 75 in src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs#L75

Added line #L75 was not covered by tests
}

return JsonSerializer.Deserialize<T>(ref reader, options);

Check warning on line 78 in src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs#L78

Added line #L78 was not covered by tests
}

public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
{
writer.WriteStartObject();
writer.WritePropertyName("value");

Check warning on line 84 in src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs#L83-L84

Added lines #L83 - L84 were not covered by tests

if (value is WrappedMessageBody body)
{
JsonSerializer.Serialize(writer, body.Value, body.Value.GetType(), options);

Check warning on line 88 in src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs#L88

Added line #L88 was not covered by tests
}
else
writer.WriteNullValue();
onionhammer marked this conversation as resolved.
Show resolved Hide resolved
writer.WriteEndObject();
}

Check warning on line 93 in src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonConverter.cs#L91-L93

Added lines #L91 - L93 were not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// ------------------------------------------------------------------------
// Copyright 2021 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------

namespace Dapr.Actors.Communication
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Threading.Tasks;
using System.Xml;

/// <summary>
/// This is the implmentation for <see cref="IActorMessageBodySerializationProvider"/>used by remoting service and client during
/// request/response serialization . It uses request Wrapping and data contract for serialization.
/// </summary>
internal class ActorMessageBodyJsonSerializationProvider : IActorMessageBodySerializationProvider
{
public JsonSerializerOptions Options { get; }

Check warning on line 29 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L29

Added line #L29 was not covered by tests

/// <summary>
/// Initializes a new instance of the <see cref="ActorMessageBodyJsonSerializationProvider"/> class.
/// </summary>
public ActorMessageBodyJsonSerializationProvider(JsonSerializerOptions options)

Check warning on line 34 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L34

Added line #L34 was not covered by tests
{
Options = options;
}

Check warning on line 37 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L36-L37

Added lines #L36 - L37 were not covered by tests

/// <summary>
/// Creates a MessageFactory for Wrapped Message Json Remoting Types. This is used to create Remoting Request/Response objects.
/// </summary>
/// <returns>
/// <see cref="IActorMessageBodyFactory" /> that provides an instance of the factory for creating
/// remoting request and response message bodies.
/// </returns>
public IActorMessageBodyFactory CreateMessageBodyFactory()
{
return new WrappedRequestMessageFactory();

Check warning on line 48 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L48

Added line #L48 was not covered by tests
}

/// <summary>
/// Creates IActorRequestMessageBodySerializer for a serviceInterface using Wrapped Message Json implementation.
/// </summary>
/// <param name="serviceInterfaceType">The remoted service interface.</param>
/// <param name="methodRequestParameterTypes">The union of parameter types of all of the methods of the specified interface.</param>
/// <param name="wrappedRequestMessageTypes">Wrapped Request Types for all Methods.</param>
/// <returns>
/// An instance of the <see cref="IActorRequestMessageBodySerializer" /> that can serialize the service
/// actor request message body to a messaging body for transferring over the transport.
/// </returns>
public IActorRequestMessageBodySerializer CreateRequestMessageBodySerializer(
Type serviceInterfaceType,
IEnumerable<Type> methodRequestParameterTypes,
IEnumerable<Type> wrappedRequestMessageTypes = null)
{
return new MemoryStreamMessageBodySerializer<WrappedMessageBody, WrappedMessageBody>(Options, serviceInterfaceType, methodRequestParameterTypes, wrappedRequestMessageTypes);

Check warning on line 66 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L66

Added line #L66 was not covered by tests
}

/// <summary>
/// Creates IActorResponseMessageBodySerializer for a serviceInterface using Wrapped Message Json implementation.
/// </summary>
/// <param name="serviceInterfaceType">The remoted service interface.</param>
/// <param name="methodReturnTypes">The return types of all of the methods of the specified interface.</param>
/// <param name="wrappedResponseMessageTypes">Wrapped Response Types for all remoting methods.</param>
/// <returns>
/// An instance of the <see cref="IActorResponseMessageBodySerializer" /> that can serialize the service
/// actor response message body to a messaging body for transferring over the transport.
/// </returns>
public IActorResponseMessageBodySerializer CreateResponseMessageBodySerializer(
Type serviceInterfaceType,
IEnumerable<Type> methodReturnTypes,
IEnumerable<Type> wrappedResponseMessageTypes = null)
{
return new MemoryStreamMessageBodySerializer<WrappedMessageBody, WrappedMessageBody>(Options, serviceInterfaceType, methodReturnTypes, wrappedResponseMessageTypes);

Check warning on line 84 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L84

Added line #L84 was not covered by tests
}

/// <summary>
/// Default serializer for service remoting request and response message body that uses the
/// memory stream to create outgoing message buffers.
/// </summary>
private class MemoryStreamMessageBodySerializer<TRequest, TResponse> :
IActorRequestMessageBodySerializer,
IActorResponseMessageBodySerializer
where TRequest : IActorRequestMessageBody
where TResponse : IActorResponseMessageBody
{
private readonly JsonSerializerOptions serializerOptions;

public MemoryStreamMessageBodySerializer(
JsonSerializerOptions serializerOptions,
Type serviceInterfaceType,
IEnumerable<Type> methodRequestParameterTypes,
IEnumerable<Type> wrappedRequestMessageTypes = null)

Check warning on line 103 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L99-L103

Added lines #L99 - L103 were not covered by tests
{
var _methodRequestParameterTypes = new List<Type>(methodRequestParameterTypes);
var _wrappedRequestMessageTypes = new List<Type>(wrappedRequestMessageTypes);

Check warning on line 106 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L105-L106

Added lines #L105 - L106 were not covered by tests

this.serializerOptions = new(serializerOptions)
{
// Workaround since WrappedMessageBody creates an object
// with parameters as fields
IncludeFields = true,
};

Check warning on line 113 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L108-L113

Added lines #L108 - L113 were not covered by tests

this.serializerOptions.Converters.Add(new ActorMessageBodyJsonConverter<TRequest>(_methodRequestParameterTypes, _wrappedRequestMessageTypes));
this.serializerOptions.Converters.Add(new ActorMessageBodyJsonConverter<TResponse>(_methodRequestParameterTypes, _wrappedRequestMessageTypes));
}

Check warning on line 117 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L115-L117

Added lines #L115 - L117 were not covered by tests

byte[] IActorRequestMessageBodySerializer.Serialize(IActorRequestMessageBody actorRequestMessageBody)
{
if (actorRequestMessageBody == null)
{
return null;

Check warning on line 123 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L123

Added line #L123 was not covered by tests
}

return JsonSerializer.SerializeToUtf8Bytes<object>(actorRequestMessageBody, this.serializerOptions);

Check warning on line 126 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L126

Added line #L126 was not covered by tests
}

async ValueTask<IActorRequestMessageBody> IActorRequestMessageBodySerializer.DeserializeAsync(Stream stream)
{
if (stream == null)
{
return default;

Check warning on line 133 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L133

Added line #L133 was not covered by tests
}

if (stream.Length == 0)
{
return default;

Check warning on line 138 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L138

Added line #L138 was not covered by tests
}

stream.Position = 0;

Check warning on line 141 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L141

Added line #L141 was not covered by tests
return await JsonSerializer.DeserializeAsync<TRequest>(stream, this.serializerOptions);
}

Check warning on line 143 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L143

Added line #L143 was not covered by tests

byte[] IActorResponseMessageBodySerializer.Serialize(IActorResponseMessageBody actorResponseMessageBody)
{
if (actorResponseMessageBody == null)
{
return null;

Check warning on line 149 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L149

Added line #L149 was not covered by tests
}

return JsonSerializer.SerializeToUtf8Bytes<object>(actorResponseMessageBody, this.serializerOptions);

Check warning on line 152 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L152

Added line #L152 was not covered by tests
}

async ValueTask<IActorResponseMessageBody> IActorResponseMessageBodySerializer.DeserializeAsync(Stream messageBody)
{
if (messageBody == null)
{
return null;

Check warning on line 159 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L159

Added line #L159 was not covered by tests
}

using var stream = new MemoryStream();
messageBody.CopyTo(stream);
stream.Position = 0;

Check warning on line 164 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L162-L164

Added lines #L162 - L164 were not covered by tests

if (stream.Capacity == 0)
{
return null;

Check warning on line 168 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L168

Added line #L168 was not covered by tests
}

return await JsonSerializer.DeserializeAsync<TResponse>(stream, this.serializerOptions);
}

Check warning on line 172 in src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/Dapr.Actors/Communication/ActorMessageBodyJsonSerializationProvider.cs#L172

Added line #L172 was not covered by tests
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Dapr.Actors.Communication
{
using System.IO;
using System.Threading.Tasks;

/// <summary>
/// Defines the interface that must be implemented to provide a serializer/deserializer for remoting request message body.
Expand All @@ -32,6 +33,6 @@ internal interface IActorRequestMessageBodySerializer
/// </summary>
/// <param name="messageBody">Serialized message body.</param>
/// <returns>Deserialized remoting request message body object.</returns>
IActorRequestMessageBody Deserialize(Stream messageBody);
ValueTask<IActorRequestMessageBody> DeserializeAsync(Stream messageBody);
}
}
Loading
Loading