Skip to content

Commit

Permalink
Major Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor committed Jan 8, 2025
1 parent ea1a5d8 commit 5628420
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
14 changes: 7 additions & 7 deletions src/UUID.Serialization.Newtonsoft/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,28 @@ string json = JsonConvert.SerializeObject(user);

## Features

- Seamless integration with Newtonsoft.Json
- Support for null handling
- Thread-safe implementation
- Efficient string conversion
- Comprehensive error handling
- Thread-safe implementation
- Support for JsonConverter attribute
- Full documentation with XML comments
- Support for null handling
- Seamless integration with Newtonsoft.Json
- Custom error messages for better debugging
- Support for JsonConverter attribute

## Error Handling

The converter provides detailed error messages for common scenarios:

- Null values: "Cannot convert null value to UUID"
- Invalid string formats: Includes the attempted value in error message
- Empty strings: "Cannot convert empty string to UUID"
- Incorrect JSON types: Shows expected vs actual type
- Empty strings: "Cannot convert empty string to UUID"
- Invalid string formats: Includes the attempted value in error message

## Requirements

- .NET 9.0 or later
- UUID library
- .NET 9.0 or later
- Newtonsoft.Json 13.0.3 or later

## Contributing
Expand Down
12 changes: 6 additions & 6 deletions src/UUID.Serialization.System/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ UserModel deserializedUser = JsonSerializer.Deserialize<UserModel>(json, options

## Features

- Seamless integration with System.Text.Json
- Support for null handling
- Thread-safe implementation
- Efficient string conversion
- Comprehensive error handling
- Thread-safe implementation
- Full documentation with XML comments
- Support for null handling
- Seamless integration with System.Text.Json
- Custom error messages for better debugging

## Error Handling

The converter provides detailed error messages for common scenarios:

- Null values: "Cannot convert null value to UUID"
- Invalid string formats: Includes the attempted value in error message
- Empty strings: "Cannot convert empty string to UUID"
- Incorrect JSON types: Shows expected vs actual type
- Empty strings: "Cannot convert empty string to UUID"
- Invalid string formats: Includes the attempted value in error message

## Requirements

- .NET 9.0 or later
- UUID library
- .NET 9.0 or later
- System.Text.Json 9.0.0 or later

## Contributing
Expand Down
28 changes: 14 additions & 14 deletions src/UUID/Constructor/UUID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public readonly partial struct UUID(ulong timestamp, ulong random) : IEquatable<
/// <summary>
/// The timestamp component of the UUID.
/// </summary>
internal readonly ulong _timestamp = timestamp;
public ulong Timestamp { get; } = timestamp;

Check warning on line 96 in src/UUID/Constructor/UUID.cs

View workflow job for this annotation

GitHub Actions / Build (Release, UUID.sln)

Parameter 'ulong timestamp' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

Check warning on line 96 in src/UUID/Constructor/UUID.cs

View workflow job for this annotation

GitHub Actions / Build (Release, UUID.sln)

Parameter 'ulong timestamp' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

Check warning on line 96 in src/UUID/Constructor/UUID.cs

View workflow job for this annotation

GitHub Actions / Build (Release, UUID.sln)

Parameter 'ulong timestamp' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

Check warning on line 96 in src/UUID/Constructor/UUID.cs

View workflow job for this annotation

GitHub Actions / Build (Release, UUID.sln)

Parameter 'ulong timestamp' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

Check warning on line 96 in src/UUID/Constructor/UUID.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp, Release, UUID.sln)

Parameter 'ulong timestamp' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

Check warning on line 96 in src/UUID/Constructor/UUID.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp, Release, UUID.sln)

Parameter 'ulong timestamp' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

Check warning on line 96 in src/UUID/Constructor/UUID.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp, Release, UUID.sln)

Parameter 'ulong timestamp' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

/// <summary>
/// Characters used in Base32 encoding.
Expand Down Expand Up @@ -225,7 +225,7 @@ private static ulong GenerateTimestamp()
/// </returns>
public static int CompareTimestamps(UUID a, UUID b)
{
return a._timestamp.CompareTo(b._timestamp);
return a.Timestamp.CompareTo(b.Timestamp);
}

/// <summary>
Expand All @@ -234,7 +234,7 @@ public static int CompareTimestamps(UUID a, UUID b)
/// <returns>The counter value used for ordering within the same millisecond.</returns>
public ushort GetMonotonicCounter()
{
return (ushort)(Random & 0xFFF); // Extract last 12 bits
return (ushort)(random & 0xFFF); // Extract last 12 bits
}

/// <summary>
Expand Down Expand Up @@ -348,9 +348,9 @@ private static ulong GenerateRandom()
/// </remarks>
public bool IsOrderedAfter(UUID other)
{
if (_timestamp != other._timestamp)
if (timestamp != other.Timestamp)
{
return _timestamp > other._timestamp;
return timestamp > other.Timestamp;
}

return GetMonotonicCounter() > other.GetMonotonicCounter();
Expand Down Expand Up @@ -436,15 +436,15 @@ public static bool TryParse(string? input, out UUID result)
/// <summary>
/// Gets the timestamp component of the UUID.
/// </summary>
public DateTimeOffset Time => DateTimeOffset.FromUnixTimeMilliseconds((long)(_timestamp >> 16));
public DateTimeOffset Time => DateTimeOffset.FromUnixTimeMilliseconds((long)(timestamp >> 16));

/// <summary>
/// Returns a string representation of the UUID.
/// </summary>
/// <returns>A string representation of the UUID.</returns>
public override string ToString()
{
return $"{_timestamp:X16}{Random:X16}";
return $"{timestamp:X16}{random:X16}";
}

/// <summary>
Expand All @@ -464,7 +464,7 @@ public override string ToString()
public long ToInt64()
{
// Use the timestamp as the base (48 bits)
long result = (long)(_timestamp >> 16); // Get the milliseconds part
long result = (long)(timestamp >> 16); // Get the milliseconds part

// Generate a 15-bit hash from the full random component
ulong fullRandom = random;
Expand Down Expand Up @@ -495,7 +495,7 @@ public static implicit operator long(UUID uuid)
public string ToBase32()
{
char[] result = new char[26];
ulong value = _timestamp;
ulong value = timestamp;

for (int i = 25; i >= 0; i--)
{
Expand Down Expand Up @@ -626,7 +626,7 @@ public bool TryWriteBytes(Span<byte> destination)
return false;
}

BitConverter.TryWriteBytes(destination[..8], _timestamp);
BitConverter.TryWriteBytes(destination[..8], timestamp);
BitConverter.TryWriteBytes(destination[8..], random);

return true;
Expand All @@ -639,7 +639,7 @@ public bool TryWriteBytes(byte[] destination)
return false;
}

byte[] timestampBytes = BitConverter.GetBytes(_timestamp);
byte[] timestampBytes = BitConverter.GetBytes(timestamp);
byte[] randomBytes = BitConverter.GetBytes(random);

Array.Copy(timestampBytes, 0, destination, 0, 8);
Expand Down Expand Up @@ -778,7 +778,7 @@ public static bool TryFromByteArray(byte[] bytes, out UUID result)
/// <returns>true if the specified UUID is equal to the current UUID; otherwise, false.</returns>
public bool Equals(UUID other)
{
return _timestamp == other._timestamp && random == other.Random;
return timestamp == other.Timestamp && random == other.Random;
}

/// <summary>
Expand Down Expand Up @@ -894,7 +894,7 @@ public override int GetHashCode()
{
unchecked
{
return (_timestamp.GetHashCode() * 397) ^ random.GetHashCode();
return (timestamp.GetHashCode() * 397) ^ random.GetHashCode();
}
}

Expand All @@ -910,7 +910,7 @@ public override int GetHashCode()
/// </returns>
public int CompareTo(UUID other)
{
int result = _timestamp.CompareTo(other._timestamp);
int result = timestamp.CompareTo(other.Timestamp);

return result != 0 ? result : random.CompareTo(other.Random);
}
Expand Down

0 comments on commit 5628420

Please sign in to comment.