Skip to content

Commit

Permalink
Remove unnecessary stream; directly use serializetobytes
Browse files Browse the repository at this point in the history
  • Loading branch information
onionhammer committed Aug 21, 2023
1 parent 2479f5d commit 4c2cd18
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<T>(ref reader, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,7 @@ byte[] IActorRequestMessageBodySerializer.Serialize(IActorRequestMessageBody act
return null;
}

using var stream = new MemoryStream();
using var writer = new Utf8JsonWriter(stream);
JsonSerializer.Serialize<object>(writer, actorRequestMessageBody, this.serializerOptions);
writer.Flush();

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

async ValueTask<IActorRequestMessageBody> IActorRequestMessageBodySerializer.DeserializeAsync(Stream stream)
Expand All @@ -154,12 +149,7 @@ byte[] IActorResponseMessageBodySerializer.Serialize(IActorResponseMessageBody a
return null;
}

using var stream = new MemoryStream();
using var writer = new Utf8JsonWriter(stream);
JsonSerializer.Serialize<object>(writer, actorResponseMessageBody, this.serializerOptions);
writer.Flush();

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

async ValueTask<IActorResponseMessageBody> IActorResponseMessageBodySerializer.DeserializeAsync(Stream messageBody)
Expand Down

0 comments on commit 4c2cd18

Please sign in to comment.