-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from HongGeonUi/randEvent
feat: Add RandEvent, RandEventParser
- Loading branch information
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace MySqlCdc.Events; | ||
|
||
/// <summary> | ||
/// Represents two seed values that set the rand_seed1 and rand_seed2 system variables that are used to compute the random number. | ||
/// <a href="https://mariadb.com/kb/en/rand_event/">See more</a> | ||
/// </summary> | ||
/// <remarks> | ||
/// Creates a new <see cref="RandEvent"/>. | ||
/// </remarks> | ||
public record RandEvent(ulong Seed1, ulong Seed2) : IBinlogEvent | ||
{ | ||
/// <summary> | ||
/// Gets the rand_seed1 | ||
/// </summary> | ||
public ulong Seed1 {get; } = Seed1; | ||
|
||
/// <summary> | ||
/// Gets the rand_seed2 | ||
/// </summary> | ||
public ulong Seed2 { get; } = Seed2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using MySqlCdc.Events; | ||
using MySqlCdc.Protocol; | ||
|
||
namespace MySqlCdc.Parsers; | ||
|
||
/// <summary> | ||
/// Parses <see cref="RandEvent"/> events. | ||
/// Supports all versions of MariaDB and MySQL. | ||
/// </summary> | ||
|
||
public class RandEventParser : IEventParser | ||
{ | ||
/// <summary> | ||
/// Parses <see cref="RandEvent"/> from the buffer. | ||
/// </summary> | ||
public IBinlogEvent ParseEvent(EventHeader header, ref PacketReader reader) | ||
{ | ||
var seed1 = reader.ReadUInt64LittleEndian(); | ||
var seed2 = reader.ReadUInt64LittleEndian(); | ||
|
||
return new RandEvent(seed1, seed2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
using MySqlCdc.Events; | ||
using MySqlCdc.Parsers; | ||
using MySqlCdc.Protocol; | ||
using Xunit; | ||
|
||
namespace MySqlCdc.Tests.Parsers; | ||
|
||
public class RandEventParserTests | ||
{ | ||
private static byte[] Payload = { | ||
0x5f, 0x56, 0x75, 0x65, 0x0d, 0x01, 0x00, 0x00, 0x00, 0x27, 0x00, | ||
0x00, 0x00, 0x02, 0x07, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xdb, 0x85, 0x2d, 0x00, 0x00, | ||
0x00, 0x00, 0x07, 0x97, 0xbc, 0x04, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x6e, 0x46, 0xdd | ||
}; | ||
|
||
[Fact] | ||
public void Test_RandEvent_ReturnsEvent() | ||
{ | ||
var reader = new PacketReader(Payload); | ||
var eventHeader = EventHeader.Read(ref reader); | ||
|
||
var parser = new RandEventParser(); | ||
var @event = (RandEvent)parser.ParseEvent(eventHeader, ref reader); | ||
; | ||
Assert.Equal(763747084UL, @event.Seed1); | ||
Assert.Equal(79468295UL, @event.Seed2); | ||
} | ||
} |