Skip to content

Commit

Permalink
Merge branch 'steam-login' of https://github.com/Nexus-Mods/NexusMods…
Browse files Browse the repository at this point in the history
….App into steam-login
  • Loading branch information
halgari committed Dec 17, 2024
2 parents 6cca217 + a5dd382 commit 71c769a
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,31 @@ namespace NexusMods.Abstractions.Hashes;
/// </summary>
public class HashJsonConverter : JsonConverter<Hash>
{
/// <inheritdoc/>
public override Hash Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
Span<byte> chars = stackalloc byte[8];
Convert.FromHexString(reader.GetString()!, chars, out _, out _);
return Hash.FromULong(MemoryMarshal.Read<ulong>(chars));
var input = reader.GetString();
if (input is null) throw new JsonException();

Span<byte> bytes = stackalloc byte[sizeof(ulong)];

var status = Convert.FromHexString(input, bytes, out _, out _);
Debug.Assert(status == OperationStatus.Done);

Check failure on line 22 in src/Abstractions/NexusMods.Abstractions.Hashes/HashJsonConverter.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (ubuntu-latest)

The name 'Debug' does not exist in the current context

Check failure on line 22 in src/Abstractions/NexusMods.Abstractions.Hashes/HashJsonConverter.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (ubuntu-latest)

The name 'OperationStatus' does not exist in the current context

Check failure on line 22 in src/Abstractions/NexusMods.Abstractions.Hashes/HashJsonConverter.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (ubuntu-latest)

The name 'Debug' does not exist in the current context

Check failure on line 22 in src/Abstractions/NexusMods.Abstractions.Hashes/HashJsonConverter.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (ubuntu-latest)

The name 'OperationStatus' does not exist in the current context

Check failure on line 22 in src/Abstractions/NexusMods.Abstractions.Hashes/HashJsonConverter.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-latest)

The name 'Debug' does not exist in the current context

Check failure on line 22 in src/Abstractions/NexusMods.Abstractions.Hashes/HashJsonConverter.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-latest)

The name 'OperationStatus' does not exist in the current context

Check failure on line 22 in src/Abstractions/NexusMods.Abstractions.Hashes/HashJsonConverter.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-latest)

The name 'Debug' does not exist in the current context

Check failure on line 22 in src/Abstractions/NexusMods.Abstractions.Hashes/HashJsonConverter.cs

View workflow job for this annotation

GitHub Actions / build

The name 'Debug' does not exist in the current context

Check failure on line 22 in src/Abstractions/NexusMods.Abstractions.Hashes/HashJsonConverter.cs

View workflow job for this annotation

GitHub Actions / build

The name 'OperationStatus' does not exist in the current context

Check failure on line 22 in src/Abstractions/NexusMods.Abstractions.Hashes/HashJsonConverter.cs

View workflow job for this annotation

GitHub Actions / build-linux / build-appimage

The name 'Debug' does not exist in the current context

Check failure on line 22 in src/Abstractions/NexusMods.Abstractions.Hashes/HashJsonConverter.cs

View workflow job for this annotation

GitHub Actions / build-linux / build-appimage

The name 'OperationStatus' does not exist in the current context

var value = MemoryMarshal.Read<ulong>(bytes);
return Hash.FromULong(value);
}

/// <inheritdoc/>
public override void Write(Utf8JsonWriter writer, Hash value, JsonSerializerOptions options)
{
Span<char> span = stackalloc char[16];
Span<byte> bytes = stackalloc byte[8];
Span<char> span = stackalloc char[sizeof(ulong) * 2];
Span<byte> bytes = stackalloc byte[sizeof(ulong)];
MemoryMarshal.Write(bytes, value.Value);
Convert.TryToHexString(bytes, span, out _);

var success = Convert.TryToHexString(bytes, span, out _);
Debug.Assert(success);

Check failure on line 36 in src/Abstractions/NexusMods.Abstractions.Hashes/HashJsonConverter.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (ubuntu-latest)

The name 'Debug' does not exist in the current context

Check failure on line 36 in src/Abstractions/NexusMods.Abstractions.Hashes/HashJsonConverter.cs

View workflow job for this annotation

GitHub Actions / build-and-test / Build and Test (macos-latest)

The name 'Debug' does not exist in the current context

Check failure on line 36 in src/Abstractions/NexusMods.Abstractions.Hashes/HashJsonConverter.cs

View workflow job for this annotation

GitHub Actions / build

The name 'Debug' does not exist in the current context

Check failure on line 36 in src/Abstractions/NexusMods.Abstractions.Hashes/HashJsonConverter.cs

View workflow job for this annotation

GitHub Actions / build-linux / build-appimage

The name 'Debug' does not exist in the current context

writer.WriteStringValue(span);
}
}

0 comments on commit 71c769a

Please sign in to comment.