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

Use singular helper when creating checksums #72849

Merged
merged 4 commits into from
Apr 2, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use singular helper when creating checksumsw
  • Loading branch information
CyrusNajmabadi committed Apr 2, 2024
commit 0afa747a0838d22f25b258172a4173c5aa022074
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ public static Checksum Create(Stream stream)
return From(hash);
}

public static Checksum Create<T>(T @object, Action<T, ObjectWriter> writeObject)
{
using var stream = SerializableBytes.CreateWritableStream();

using (var objectWriter = new ObjectWriter(stream, leaveOpen: true))
{
writeObject(@object, objectWriter);
}

stream.Position = 0;
return Create(stream);
}

public static Checksum Create(Checksum checksum1, Checksum checksum2)
=> Create(stackalloc[] { checksum1, checksum2 });

Expand Down Expand Up @@ -104,17 +117,4 @@ public static Checksum Create<T>(T value, ISerializerService serializer)
serializer.Serialize(value!, writer, context, CancellationToken.None);
});
}

public static Checksum Create<T>(T value, Action<T, ObjectWriter> writeTo)
{
using var stream = SerializableBytes.CreateWritableStream();

using (var objectWriter = new ObjectWriter(stream, leaveOpen: true))
{
writeTo(value, objectWriter);
}

stream.Position = 0;
return Create(stream);
}
}
Loading