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

Support serializing received message to/from AMQP bytes #33682

Merged
merged 15 commits into from
Feb 2, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,14 @@ public virtual Guid ParseGuidBytes(ReadOnlyMemory<byte> bytes)
{
if (bytes.Length == GuidSizeInBytes)
{
return new Guid(bytes.Span.ToArray());
// Use TryRead to avoid allocating an array
if (!MemoryMarshal.TryRead<Guid>(bytes.Span, out var lockTokenGuid))
JoshLove-msft marked this conversation as resolved.
Show resolved Hide resolved
{
// We expect the constructor to fail at this point, but we invoke it to leverage the Guid validation rather than
// throwing ourselves.
lockTokenGuid = new Guid(bytes.ToArray());
}
return lockTokenGuid;
}

return default;
Expand Down