Skip to content

Commit

Permalink
Update type of seeds to be unsigned long instead of long
Browse files Browse the repository at this point in the history
  • Loading branch information
dongwook-chan committed Dec 10, 2023
1 parent 953454a commit 605be73
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/MySqlCdc/Events/RandEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ namespace MySqlCdc.Events;
/// <remarks>
/// Creates a new <see cref="RandEvent"/>.
/// </remarks>
public record RandEvent(long Seed1, long Seed2) : IBinlogEvent
public record RandEvent(ulong Seed1, ulong Seed2) : IBinlogEvent
{
/// <summary>
/// Gets the rand_seed1
/// </summary>
public long Seed1 {get; } = Seed1;
public ulong Seed1 {get; } = Seed1;

/// <summary>
/// Gets the rand_seed2
/// </summary>
public long Seed2 {get; } = Seed2;

public ulong Seed2 { get; } = Seed2;
}
4 changes: 2 additions & 2 deletions src/MySqlCdc/Parsers/RandEventParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class RandEventParser : IEventParser
/// </summary>
public IBinlogEvent ParseEvent(EventHeader header, ref PacketReader reader)
{
var seed1 = reader.ReadInt64LittleEndian();
var seed2 = reader.ReadInt64LittleEndian();
var seed1 = reader.ReadUInt64LittleEndian();
var seed2 = reader.ReadUInt64LittleEndian();

return new RandEvent(seed1, seed2);
}
Expand Down
10 changes: 10 additions & 0 deletions src/MySqlCdc/Protocol/PacketReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public UInt32 ReadUInt32BigEndian()
return result;
}

/// <summary>
/// Reads 64-bit long written in little-endian format.
/// </summary>
public UInt64 ReadUInt64LittleEndian()
{
UInt64 result = BinaryPrimitives.ReadUInt64LittleEndian(_span.Slice(_offset));
_offset += 8;
return result;
}

/// <summary>
/// Reads 64-bit long written in little-endian format.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions tests/MySqlCdc.Tests/Parsers/RandEventParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void Test_RandEvent_ReturnsEvent()
var parser = new RandEventParser();
var @event = (RandEvent)parser.ParseEvent(eventHeader, ref reader);
;
Assert.Equal(763747084, @event.Seed1);
Assert.Equal(79468295, @event.Seed2);
Assert.Equal(763747084UL, @event.Seed1);
Assert.Equal(79468295UL, @event.Seed2);
}
}

0 comments on commit 605be73

Please sign in to comment.