diff --git a/src/MySqlCdc/BinlogReader.cs b/src/MySqlCdc/BinlogReader.cs index ed8a306..cf67441 100644 --- a/src/MySqlCdc/BinlogReader.cs +++ b/src/MySqlCdc/BinlogReader.cs @@ -77,7 +77,7 @@ private EventHeader GetEventHeader(ReadOnlySequence buffer) { using var memoryOwner = new MemoryOwner(buffer.Slice(0, EventConstants.HeaderSize)); var reader = new PacketReader(memoryOwner.Memory.Span); - return new EventHeader(ref reader); + return EventHeader.Read(ref reader); } private HeaderWithEvent Deserialize(ReadOnlySequence packet) diff --git a/src/MySqlCdc/Events/DeleteRowsEvent.cs b/src/MySqlCdc/Events/DeleteRowsEvent.cs index 2b0dd9a..2e30ac8 100644 --- a/src/MySqlCdc/Events/DeleteRowsEvent.cs +++ b/src/MySqlCdc/Events/DeleteRowsEvent.cs @@ -4,47 +4,38 @@ namespace MySqlCdc.Events; /// Represents one or many deleted rows in row based replication. /// See more /// -public class DeleteRowsEvent : IBinlogEvent +/// +/// Creates a new . +/// +public record DeleteRowsEvent( + long TableId, + int Flags, + int ColumnsNumber, + bool[] ColumnsPresent, + IReadOnlyList Rows) : IBinlogEvent { /// /// Gets id of the table where rows were deleted /// - public long TableId { get; } + public long TableId { get; } = TableId; /// /// Gets flags /// - public int Flags { get; } + public int Flags { get; } = Flags; /// /// Gets number of columns in the table /// - public int ColumnsNumber { get; } + public int ColumnsNumber { get; } = ColumnsNumber; /// /// Gets bitmap of columns present in row event. See binlog_row_image parameter. /// - public bool[] ColumnsPresent { get; } + public bool[] ColumnsPresent { get; } = ColumnsPresent; /// /// Gets deleted rows /// - public IReadOnlyList Rows { get; } - - /// - /// Creates a new . - /// - public DeleteRowsEvent( - long tableId, - int flags, - int columnsNumber, - bool[] columnsPresent, - IReadOnlyList rows) - { - TableId = tableId; - Flags = flags; - ColumnsNumber = columnsNumber; - ColumnsPresent = columnsPresent; - Rows = rows; - } + public IReadOnlyList Rows { get; } = Rows; } \ No newline at end of file diff --git a/src/MySqlCdc/Events/EventDeserializer.cs b/src/MySqlCdc/Events/EventDeserializer.cs index 32e29fb..e136460 100644 --- a/src/MySqlCdc/Events/EventDeserializer.cs +++ b/src/MySqlCdc/Events/EventDeserializer.cs @@ -53,7 +53,7 @@ protected EventDeserializer() internal virtual HeaderWithEvent DeserializeEvent(ref PacketReader reader) { - var eventHeader = new EventHeader(ref reader); + var eventHeader = EventHeader.Read(ref reader); // Consider verifying checksum // ChecksumType.Verify(eventBuffer, checksumBuffer); diff --git a/src/MySqlCdc/Events/EventHeader.cs b/src/MySqlCdc/Events/EventHeader.cs index 39c0ecd..5e1c5eb 100644 --- a/src/MySqlCdc/Events/EventHeader.cs +++ b/src/MySqlCdc/Events/EventHeader.cs @@ -8,48 +8,56 @@ namespace MySqlCdc.Events; /// See MariaDB docs /// See MySQL docs /// -public class EventHeader +public record EventHeader( + long Timestamp, + EventType EventType, + long ServerId, + long EventLength, + long NextEventPosition, + int EventFlags) { /// /// Provides creation time in seconds from Unix. /// - public long Timestamp { get; } + public long Timestamp { get; } = Timestamp; /// /// Gets type of the binlog event. /// - public EventType EventType { get; } + public EventType EventType { get; } = EventType; /// /// Gets id of the server that created the event. /// - public long ServerId { get; } + public long ServerId { get; } = ServerId; /// /// Gets event length (header + event + checksum). /// - public long EventLength { get; } + public long EventLength { get; } = EventLength; /// /// Gets file position of next event. /// - public long NextEventPosition { get; } + public long NextEventPosition { get; } = NextEventPosition; /// /// Gets event flags. See documentation. /// - public int EventFlags { get; } + public int EventFlags { get; } = EventFlags; /// /// Creates a new . /// - public EventHeader(ref PacketReader reader) + public static EventHeader Read(ref PacketReader reader) { - Timestamp = reader.ReadUInt32LittleEndian(); - EventType = (EventType)reader.ReadByte(); - ServerId = reader.ReadUInt32LittleEndian(); - EventLength = reader.ReadUInt32LittleEndian(); - NextEventPosition = reader.ReadUInt32LittleEndian(); - EventFlags = reader.ReadUInt16LittleEndian(); + return new EventHeader( + reader.ReadUInt32LittleEndian(), + (EventType)reader.ReadByte(), + reader.ReadUInt32LittleEndian(), + reader.ReadUInt32LittleEndian(), + reader.ReadUInt32LittleEndian(), + reader.ReadUInt16LittleEndian() + ); } } \ No newline at end of file diff --git a/src/MySqlCdc/Events/EventWithHeader.cs b/src/MySqlCdc/Events/EventWithHeader.cs index cf4564e..b712438 100644 --- a/src/MySqlCdc/Events/EventWithHeader.cs +++ b/src/MySqlCdc/Events/EventWithHeader.cs @@ -2,14 +2,4 @@ namespace MySqlCdc.Events; -internal class HeaderWithEvent : IPacket -{ - public EventHeader Header { get; } - public IBinlogEvent Event { get; } - - public HeaderWithEvent(EventHeader header, IBinlogEvent @event) - { - Header = header; - Event = @event; - } -} \ No newline at end of file +internal record HeaderWithEvent(EventHeader Header, IBinlogEvent Event) : IPacket; \ No newline at end of file diff --git a/src/MySqlCdc/Events/FormatDescriptionEvent.cs b/src/MySqlCdc/Events/FormatDescriptionEvent.cs index 8f1ec74..31bff79 100644 --- a/src/MySqlCdc/Events/FormatDescriptionEvent.cs +++ b/src/MySqlCdc/Events/FormatDescriptionEvent.cs @@ -8,33 +8,26 @@ namespace MySqlCdc.Events; /// See MySQL docs /// See start events flow /// -public class FormatDescriptionEvent : IBinlogEvent +/// +/// Creates a new . +/// +public record FormatDescriptionEvent( + int BinlogVersion, + string ServerVersion, + ChecksumType ChecksumType) : IBinlogEvent { /// /// Gets binary log format version. This should always be 4. /// - public int BinlogVersion { get; } + public int BinlogVersion { get; } = BinlogVersion; /// /// Gets MariaDB/MySQL server version name. /// - public string ServerVersion { get; } + public string ServerVersion { get; } = ServerVersion; /// /// Gets checksum algorithm type. /// - public ChecksumType ChecksumType { get; } - - /// - /// Creates a new . - /// - public FormatDescriptionEvent( - int binlogVersion, - string serverVersion, - ChecksumType checksumType) - { - BinlogVersion = binlogVersion; - ServerVersion = serverVersion; - ChecksumType = checksumType; - } + public ChecksumType ChecksumType { get; } = ChecksumType; } \ No newline at end of file diff --git a/src/MySqlCdc/Events/GtidEvent.cs b/src/MySqlCdc/Events/GtidEvent.cs index f84dc7c..1310f34 100644 --- a/src/MySqlCdc/Events/GtidEvent.cs +++ b/src/MySqlCdc/Events/GtidEvent.cs @@ -20,24 +20,18 @@ public interface IGtidState /// Marks start of a new event group(transaction). /// See more /// -public class GtidEvent : IBinlogEvent +/// +/// Creates a new . +/// +public record GtidEvent(IGtid Gtid, byte Flags) : IBinlogEvent { /// /// Gets Global Transaction ID of the event group. /// - public IGtid Gtid { get; } + public IGtid Gtid { get; } = Gtid; /// /// Gets flags. /// - public byte Flags { get; } - - /// - /// Creates a new . - /// - public GtidEvent(IGtid gtid, byte flags) - { - Gtid = gtid; - Flags = flags; - } + public byte Flags { get; } = Flags; } \ No newline at end of file diff --git a/src/MySqlCdc/Events/HeartbeatEvent.cs b/src/MySqlCdc/Events/HeartbeatEvent.cs index 8df3a98..2a50eb5 100644 --- a/src/MySqlCdc/Events/HeartbeatEvent.cs +++ b/src/MySqlCdc/Events/HeartbeatEvent.cs @@ -4,18 +4,13 @@ namespace MySqlCdc.Events; /// The event is sent from master to the client for keep alive feature. /// See more /// -public class HeartbeatEvent : IBinlogEvent +/// +/// Creates a new . +/// +public record HeartbeatEvent(string BinlogFilename) : IBinlogEvent { /// /// Gets current master binlog filename /// - public string BinlogFilename { get; } - - /// - /// Creates a new . - /// - public HeartbeatEvent(string binlogFilename) - { - BinlogFilename = binlogFilename; - } + public string BinlogFilename { get; } = BinlogFilename; } \ No newline at end of file diff --git a/src/MySqlCdc/Events/IntVarEvent.cs b/src/MySqlCdc/Events/IntVarEvent.cs index fafe442..e7067b5 100644 --- a/src/MySqlCdc/Events/IntVarEvent.cs +++ b/src/MySqlCdc/Events/IntVarEvent.cs @@ -4,7 +4,10 @@ namespace MySqlCdc.Events; /// Generated when an auto increment column or LAST_INSERT_ID() function are used. /// See more /// -public class IntVarEvent : IBinlogEvent +/// +/// Creates a new . +/// +public record IntVarEvent(byte Type, long Value) : IBinlogEvent { /// /// Gets type. @@ -12,19 +15,10 @@ public class IntVarEvent : IBinlogEvent /// 0x01 - LAST_INSERT_ID. /// 0x02 - Insert id (auto_increment). /// - public byte Type { get; } + public byte Type { get; } = Type; /// /// Gets value. /// - public long Value { get; } - - /// - /// Creates a new . - /// - public IntVarEvent(byte type, long value) - { - Type = type; - Value = value; - } + public long Value { get; } = Value; } \ No newline at end of file diff --git a/src/MySqlCdc/Events/QueryEvent.cs b/src/MySqlCdc/Events/QueryEvent.cs index 2525dd5..9b5c592 100644 --- a/src/MySqlCdc/Events/QueryEvent.cs +++ b/src/MySqlCdc/Events/QueryEvent.cs @@ -4,54 +4,44 @@ namespace MySqlCdc.Events; /// Represents sql statement in binary log. /// See more /// -public class QueryEvent : IBinlogEvent +/// +/// Creates a new . +/// +public record QueryEvent( + long ThreadId, + long Duration, + int ErrorCode, + byte[] StatusVariables, + string DatabaseName, + string SqlStatement) : IBinlogEvent { /// /// Gets id of the thread that issued the statement. /// - public long ThreadId { get; } + public long ThreadId { get; } = ThreadId; /// /// Gets the execution time of the statement in seconds. /// - public long Duration { get; } + public long Duration { get; } = Duration; /// /// Gets the error code of the executed statement. /// - public int ErrorCode { get; } + public int ErrorCode { get; } = ErrorCode; /// /// Gets status variables. /// - public byte[] StatusVariables { get; } + public byte[] StatusVariables { get; } = StatusVariables; /// /// Gets the default database name. /// - public string DatabaseName { get; } + public string DatabaseName { get; } = DatabaseName; /// /// Gets the SQL statement. /// - public string SqlStatement { get; } - - /// - /// Creates a new . - /// - public QueryEvent( - long threadId, - long duration, - int errorCode, - byte[] statusVariables, - string databaseName, - string sqlStatement) - { - ThreadId = threadId; - Duration = duration; - ErrorCode = errorCode; - StatusVariables = statusVariables; - DatabaseName = databaseName; - SqlStatement = sqlStatement; - } + public string SqlStatement { get; } = SqlStatement; } \ No newline at end of file diff --git a/src/MySqlCdc/Events/RotateEvent.cs b/src/MySqlCdc/Events/RotateEvent.cs index 6aa1ca8..77fe999 100644 --- a/src/MySqlCdc/Events/RotateEvent.cs +++ b/src/MySqlCdc/Events/RotateEvent.cs @@ -5,24 +5,18 @@ namespace MySqlCdc.Events; /// Fake version is also returned when replication is started. /// See more /// -public class RotateEvent : IBinlogEvent +/// +/// Creates a new . +/// +public record RotateEvent(string BinlogFilename, long BinlogPosition) : IBinlogEvent { /// /// Gets next binlog filename /// - public string BinlogFilename { get; } + public string BinlogFilename { get; } = BinlogFilename; /// /// Gets next binlog position /// - public long BinlogPosition { get; } - - /// - /// Creates a new . - /// - public RotateEvent(string binlogFilename, long binlogPosition) - { - BinlogFilename = binlogFilename; - BinlogPosition = binlogPosition; - } + public long BinlogPosition { get; } = BinlogPosition; } \ No newline at end of file diff --git a/src/MySqlCdc/Events/RowData.cs b/src/MySqlCdc/Events/RowData.cs index 12a64f1..19380a5 100644 --- a/src/MySqlCdc/Events/RowData.cs +++ b/src/MySqlCdc/Events/RowData.cs @@ -3,43 +3,32 @@ namespace MySqlCdc.Events; /// /// Represents an inserted or deleted row in row based replication. /// -public class RowData +/// +/// Creates a new . +/// +public record RowData(IReadOnlyList Cells) { /// /// Column values of the changed row. /// - public IReadOnlyList Cells { get; } - - /// - /// Creates a new . - /// - public RowData(IReadOnlyList cells) - { - Cells = cells; - } + public IReadOnlyList Cells { get; } = Cells; } /// /// Represents an updated row in row based replication. /// -public class UpdateRowData +/// +/// Creates a new . +/// +public record UpdateRowData(RowData BeforeUpdate, RowData AfterUpdate) { /// /// Row state before it was updated. /// - public RowData BeforeUpdate { get; } + public RowData BeforeUpdate { get; } = BeforeUpdate; /// /// Actual row state after update. /// - public RowData AfterUpdate { get; } - - /// - /// Creates a new . - /// - public UpdateRowData(RowData beforeUpdate, RowData afterUpdate) - { - BeforeUpdate = beforeUpdate; - AfterUpdate = afterUpdate; - } + public RowData AfterUpdate { get; } = AfterUpdate; } \ No newline at end of file diff --git a/src/MySqlCdc/Events/RowsQueryEvent.cs b/src/MySqlCdc/Events/RowsQueryEvent.cs index 771fde8..9c084cf 100644 --- a/src/MySqlCdc/Events/RowsQueryEvent.cs +++ b/src/MySqlCdc/Events/RowsQueryEvent.cs @@ -5,18 +5,13 @@ namespace MySqlCdc.Events; /// See MySQL docs /// See MariaDB docs /// -public class RowsQueryEvent : IBinlogEvent +/// +/// Creates a new . +/// +public record RowsQueryEvent(string Query) : IBinlogEvent { /// /// Gets SQL statement /// - public string Query { get; } - - /// - /// Creates a new . - /// - public RowsQueryEvent(string query) - { - Query = query; - } + public string Query { get; } = Query; } \ No newline at end of file diff --git a/src/MySqlCdc/Events/TableMapEvent.cs b/src/MySqlCdc/Events/TableMapEvent.cs index 6fd5250..ca55cfa 100644 --- a/src/MySqlCdc/Events/TableMapEvent.cs +++ b/src/MySqlCdc/Events/TableMapEvent.cs @@ -6,61 +6,50 @@ namespace MySqlCdc.Events; /// The event has table defition for row events. /// See more /// -public class TableMapEvent : IBinlogEvent +/// +/// Creates a new . +/// +public record TableMapEvent( + long TableId, + string DatabaseName, + string TableName, + byte[] ColumnTypes, + int[] ColumnMetadata, + bool[] NullBitmap, + TableMetadata? TableMetadata) : IBinlogEvent { /// /// Gets id of the changed table /// - public long TableId { get; } + public long TableId { get; } = TableId; /// /// Gets database name of the changed table /// - public string DatabaseName { get; } + public string DatabaseName { get; } = DatabaseName; /// /// Gets name of the changed table /// - public string TableName { get; } + public string TableName { get; } = TableName; /// /// Gets column types of the changed table /// - public byte[] ColumnTypes { get; } + public byte[] ColumnTypes { get; } = ColumnTypes; /// /// Gets columns metadata /// - public int[] ColumnMetadata { get; } + public int[] ColumnMetadata { get; } = ColumnMetadata; /// /// Gets columns nullability /// - public bool[] NullBitmap { get; } + public bool[] NullBitmap { get; } = NullBitmap; /// /// Gets table metadata for MySQL 8.0.1+ /// - public TableMetadata? TableMetadata { get; } - - /// - /// Creates a new . - /// - public TableMapEvent( - long tableId, - string databaseName, - string tableName, - byte[] columnTypes, - int[] columnMetadata, - bool[] nullBitmap, - TableMetadata? tableMetadata) - { - TableId = tableId; - DatabaseName = databaseName; - TableName = tableName; - ColumnTypes = columnTypes; - ColumnMetadata = columnMetadata; - NullBitmap = nullBitmap; - TableMetadata = tableMetadata; - } + public TableMetadata? TableMetadata { get; } = TableMetadata; } \ No newline at end of file diff --git a/src/MySqlCdc/Events/UnknownEvent.cs b/src/MySqlCdc/Events/UnknownEvent.cs index 5555314..ee0643b 100644 --- a/src/MySqlCdc/Events/UnknownEvent.cs +++ b/src/MySqlCdc/Events/UnknownEvent.cs @@ -3,12 +3,7 @@ namespace MySqlCdc.Events; /// /// Represents other binlog events. /// -public class UnknownEvent : IBinlogEvent -{ - /// - /// Creates a new . - /// - public UnknownEvent() - { - } -} \ No newline at end of file +/// +/// Creates a new . +/// +public record UnknownEvent : IBinlogEvent; \ No newline at end of file diff --git a/src/MySqlCdc/Events/UpdateRowsEvent.cs b/src/MySqlCdc/Events/UpdateRowsEvent.cs index 71f4cdc..1192044 100644 --- a/src/MySqlCdc/Events/UpdateRowsEvent.cs +++ b/src/MySqlCdc/Events/UpdateRowsEvent.cs @@ -5,54 +5,44 @@ namespace MySqlCdc.Events; /// Includes versions before and after update. /// See more /// -public class UpdateRowsEvent : IBinlogEvent +/// +/// Creates a new . +/// +public record UpdateRowsEvent( + long TableId, + int Flags, + int ColumnsNumber, + bool[] ColumnsPresentBeforeUpdate, + bool[] ColumnsPresentAfterUpdate, + IReadOnlyList Rows) : IBinlogEvent { /// /// Gets id of the table where rows were updated /// - public long TableId { get; } + public long TableId { get; } = TableId; /// /// Gets flags /// - public int Flags { get; } + public int Flags { get; } = Flags; /// /// Gets number of columns in the table /// - public int ColumnsNumber { get; } + public int ColumnsNumber { get; } = ColumnsNumber; /// /// Gets bitmap of columns present in row event before update. See binlog_row_image parameter. /// - public bool[] ColumnsPresentBeforeUpdate { get; } + public bool[] ColumnsPresentBeforeUpdate { get; } = ColumnsPresentBeforeUpdate; /// /// Gets bitmap of columns present in row event after update. See binlog_row_image parameter. /// - public bool[] ColumnsPresentAfterUpdate { get; } + public bool[] ColumnsPresentAfterUpdate { get; } = ColumnsPresentAfterUpdate; /// /// Gets updated rows /// - public IReadOnlyList Rows { get; } - - /// - /// Creates a new . - /// - public UpdateRowsEvent( - long tableId, - int flags, - int columnsNumber, - bool[] columnsPresentBeforeUpdate, - bool[] columnsPresentAfterUpdate, - IReadOnlyList rows) - { - TableId = tableId; - Flags = flags; - ColumnsNumber = columnsNumber; - ColumnsPresentBeforeUpdate = columnsPresentBeforeUpdate; - ColumnsPresentAfterUpdate = columnsPresentAfterUpdate; - Rows = rows; - } + public IReadOnlyList Rows { get; } = Rows; } \ No newline at end of file diff --git a/src/MySqlCdc/Events/UserVarEvent.cs b/src/MySqlCdc/Events/UserVarEvent.cs index 6ef67a6..c772791 100644 --- a/src/MySqlCdc/Events/UserVarEvent.cs +++ b/src/MySqlCdc/Events/UserVarEvent.cs @@ -4,61 +4,47 @@ namespace MySqlCdc.Events; /// A USER_VAR_EVENT is written every time a statement uses a user defined variable. /// See more /// -public class UserVarEvent : IBinlogEvent +/// +/// Creates a new . +/// +public record UserVarEvent(string Name, VariableValue? Value) : IBinlogEvent { /// /// User variable name /// - public string Name { get; } + public string Name { get; } = Name; /// /// User variable value /// - public VariableValue? Value { get; } - - /// - /// Creates a new . - /// - public UserVarEvent(string name, VariableValue? value) - { - Name = name; - Value = value; - } + public VariableValue? Value { get; } = Value; } /// /// User variable value /// -public class VariableValue +/// +/// Creates a new . +/// +public record VariableValue(byte VariableType, int CollationNumber, string Value, byte Flags) { /// /// Variable type /// - public byte VariableType { get; } + public byte VariableType { get; } = VariableType; /// /// Collation number /// - public int CollationNumber { get; } + public int CollationNumber { get; } = CollationNumber; /// /// User variable value /// - public string Value { get; } + public string Value { get; } = Value; /// /// flags /// - public byte Flags { get; } - - /// - /// Creates a new . - /// - public VariableValue(byte variableType, int collationNumber, string value, byte flags) - { - VariableType = variableType; - CollationNumber = collationNumber; - Value = value; - Flags = flags; - } + public byte Flags { get; } = Flags; } \ No newline at end of file diff --git a/src/MySqlCdc/Events/WriteRowsEvent.cs b/src/MySqlCdc/Events/WriteRowsEvent.cs index 3d7e78c..36ebd4d 100644 --- a/src/MySqlCdc/Events/WriteRowsEvent.cs +++ b/src/MySqlCdc/Events/WriteRowsEvent.cs @@ -4,47 +4,38 @@ namespace MySqlCdc.Events; /// Represents one or many inserted rows in row based replication. /// See more /// -public class WriteRowsEvent : IBinlogEvent +/// +/// Creates a new . +/// +public record WriteRowsEvent( + long TableId, + int Flags, + int ColumnsNumber, + bool[] ColumnsPresent, + IReadOnlyList Rows) : IBinlogEvent { /// /// Gets id of the table where rows were inserted /// - public long TableId { get; } + public long TableId { get; } = TableId; /// /// Gets flags /// - public int Flags { get; } + public int Flags { get; } = Flags; /// /// Gets number of columns in the table /// - public int ColumnsNumber { get; } + public int ColumnsNumber { get; } = ColumnsNumber; /// /// Gets bitmap of columns present in row event. See binlog_row_image parameter. /// - public bool[] ColumnsPresent { get; } + public bool[] ColumnsPresent { get; } = ColumnsPresent; /// /// Gets inserted rows /// - public IReadOnlyList Rows { get; } - - /// - /// Creates a new . - /// - public WriteRowsEvent( - long tableId, - int flags, - int columnsNumber, - bool[] columnsPresent, - IReadOnlyList rows) - { - TableId = tableId; - Flags = flags; - ColumnsNumber = columnsNumber; - ColumnsPresent = columnsPresent; - Rows = rows; - } + public IReadOnlyList Rows { get; } = Rows; } \ No newline at end of file diff --git a/src/MySqlCdc/Events/XidEvent.cs b/src/MySqlCdc/Events/XidEvent.cs index 28842c6..8136647 100644 --- a/src/MySqlCdc/Events/XidEvent.cs +++ b/src/MySqlCdc/Events/XidEvent.cs @@ -4,18 +4,13 @@ namespace MySqlCdc.Events; /// Represents a transaction commit event. /// See more /// -public class XidEvent : IBinlogEvent +/// +/// Creates a new . +/// +public record XidEvent(long Xid) : IBinlogEvent { /// /// Gets the XID transaction number /// - public long Xid { get; } - - /// - /// Creates a new . - /// - public XidEvent(long xid) - { - Xid = xid; - } + public long Xid { get; } = Xid; } \ No newline at end of file diff --git a/src/MySqlCdc/Metadata/DefaultCharset.cs b/src/MySqlCdc/Metadata/DefaultCharset.cs index 2eeb454..0d33774 100644 --- a/src/MySqlCdc/Metadata/DefaultCharset.cs +++ b/src/MySqlCdc/Metadata/DefaultCharset.cs @@ -3,24 +3,18 @@ namespace MySqlCdc.Metadata; /// /// Represents charsets of character columns. /// -public class DefaultCharset +/// +/// Creates a new . +/// +public record DefaultCharset(int DefaultCharsetCollation, IReadOnlyDictionary CharsetCollations) { /// /// Gets the most used charset collation. /// - public int DefaultCharsetCollation { get; } + public int DefaultCharsetCollation { get; } = DefaultCharsetCollation; /// /// Gets ColumnIndex-Charset map for columns that don't use the default charset. /// - public IReadOnlyDictionary CharsetCollations { get; } - - /// - /// Creates a new . - /// - public DefaultCharset(int defaultCharsetCollation, IReadOnlyDictionary charsetCollations) - { - DefaultCharsetCollation = defaultCharsetCollation; - CharsetCollations = charsetCollations; - } + public IReadOnlyDictionary CharsetCollations { get; } = CharsetCollations; } \ No newline at end of file diff --git a/src/MySqlCdc/Providers/MariaDb/Events/GtidListEvent.cs b/src/MySqlCdc/Providers/MariaDb/Events/GtidListEvent.cs index b0c04cb..79d7286 100644 --- a/src/MySqlCdc/Providers/MariaDb/Events/GtidListEvent.cs +++ b/src/MySqlCdc/Providers/MariaDb/Events/GtidListEvent.cs @@ -6,18 +6,13 @@ namespace MySqlCdc.Events; /// Shows current replication state with list of last gtid for each replication domain. /// See more /// -public class GtidListEvent : IBinlogEvent +/// +/// Creates a new . +/// +public record GtidListEvent(GtidList GtidList) : IBinlogEvent { /// /// Gets a list of Gtid that represents current replication state /// - public GtidList GtidList { get; } - - /// - /// Creates a new . - /// - public GtidListEvent(GtidList gtidList) - { - GtidList = gtidList; - } + public GtidList GtidList { get; } = GtidList; } \ No newline at end of file diff --git a/src/MySqlCdc/Providers/MariaDb/Gtid/Gtid.cs b/src/MySqlCdc/Providers/MariaDb/Gtid/Gtid.cs index 36192f3..79955a6 100644 --- a/src/MySqlCdc/Providers/MariaDb/Gtid/Gtid.cs +++ b/src/MySqlCdc/Providers/MariaDb/Gtid/Gtid.cs @@ -5,32 +5,25 @@ namespace MySqlCdc.Providers.MariaDb; /// /// MariaDB 10.0.2+ representation of Gtid. /// -public class Gtid : IGtid +/// +/// Creates a new . +/// +public record Gtid(long DomainId, long ServerId, long Sequence) : IGtid { /// /// Gets domain identifier in multi-master setup. /// - public long DomainId { get; } + public long DomainId { get; } = DomainId; /// /// Gets identifier of the server that generated the event. /// - public long ServerId { get; } + public long ServerId { get; } = ServerId; /// /// Gets sequence number of the event on the original server. /// - public long Sequence { get; } - - /// - /// Creates a new . - /// - public Gtid(long domainId, long serverId, long sequence) - { - DomainId = domainId; - ServerId = serverId; - Sequence = sequence; - } + public long Sequence { get; } = Sequence; /// /// Returns string representation of Gtid in MariaDB. diff --git a/src/MySqlCdc/Providers/MySql/Events/PreviousGtidsEvent.cs b/src/MySqlCdc/Providers/MySql/Events/PreviousGtidsEvent.cs index 8c6e5b6..33fa6be 100644 --- a/src/MySqlCdc/Providers/MySql/Events/PreviousGtidsEvent.cs +++ b/src/MySqlCdc/Providers/MySql/Events/PreviousGtidsEvent.cs @@ -5,18 +5,13 @@ namespace MySqlCdc.Events; /// /// Used to record the gtid_executed of previous binlog files. /// -public class PreviousGtidsEvent : IBinlogEvent +/// +/// Creates a new . +/// +public record PreviousGtidsEvent(GtidSet GtidSet) : IBinlogEvent { /// /// Gets GtidSet of previous files. /// - public GtidSet GtidSet { get; } - - /// - /// Creates a new . - /// - public PreviousGtidsEvent(GtidSet gtidSet) - { - GtidSet = gtidSet; - } + public GtidSet GtidSet { get; } = GtidSet; } \ No newline at end of file diff --git a/src/MySqlCdc/Providers/MySql/Events/XaPrepareEvent.cs b/src/MySqlCdc/Providers/MySql/Events/XaPrepareEvent.cs index c5b6305..9bf5d42 100644 --- a/src/MySqlCdc/Providers/MySql/Events/XaPrepareEvent.cs +++ b/src/MySqlCdc/Providers/MySql/Events/XaPrepareEvent.cs @@ -3,36 +3,28 @@ namespace MySqlCdc.Events; /// /// Represents the commit event of a prepared XA transaction. /// -public class XaPrepareEvent : IBinlogEvent +/// +/// Creates a new . +/// +public record XaPrepareEvent(bool OnePhase, int FormatId, string Gtrid, string Bqual) : IBinlogEvent { /// /// XA transaction commit type. False => XA PREPARE. True => XA COMMIT ... ONE PHASE /// - public bool OnePhase { get; } + public bool OnePhase { get; } = OnePhase; /// /// The formatID part of the transaction xid. /// - public int FormatId { get; } + public int FormatId { get; } = FormatId; /// /// A global transaction identifier. /// - public string Gtrid { get; } + public string Gtrid { get; } = Gtrid; /// /// A branch qualifier. /// - public string Bqual { get; } - - /// - /// Creates a new . - /// - public XaPrepareEvent(bool onePhase, int formatId, string gtrid, string bqual) - { - OnePhase = onePhase; - FormatId = formatId; - Gtrid = gtrid; - Bqual = bqual; - } + public string Bqual { get; } = Bqual; } \ No newline at end of file diff --git a/src/MySqlCdc/Providers/MySql/Gtid/Gtid.cs b/src/MySqlCdc/Providers/MySql/Gtid/Gtid.cs index cb2205c..1851609 100644 --- a/src/MySqlCdc/Providers/MySql/Gtid/Gtid.cs +++ b/src/MySqlCdc/Providers/MySql/Gtid/Gtid.cs @@ -5,26 +5,20 @@ namespace MySqlCdc.Providers.MySql; /// /// MySQL 5.6+ representation of Gtid. /// -public class Gtid : IGtid +/// +/// Creates a new . +/// +public record Gtid(Uuid SourceId, long TransactionId) : IGtid { /// /// Gets identifier of the original server that generated the event. /// - public Uuid SourceId { get; } + public Uuid SourceId { get; } = SourceId; /// /// Gets sequence number of the event on the original server. /// - public long TransactionId { get; } - - /// - /// Creates a new . - /// - public Gtid(Uuid sourceId, long transactionId) - { - SourceId = sourceId; - TransactionId = transactionId; - } + public long TransactionId { get; } = TransactionId; /// /// Returns string representation of Gtid in MySQL Server. diff --git a/tests/MySqlCdc.Tests/Parsers/UserVarEventParserTests.cs b/tests/MySqlCdc.Tests/Parsers/UserVarEventParserTests.cs index c0ceb83..2fe8b5b 100644 --- a/tests/MySqlCdc.Tests/Parsers/UserVarEventParserTests.cs +++ b/tests/MySqlCdc.Tests/Parsers/UserVarEventParserTests.cs @@ -17,7 +17,7 @@ public class UserVarEventParserTests public void Test_UserVarEvent_ReturnsEvent() { var reader = new PacketReader(Payload); - var eventHeader = new EventHeader(ref reader); + var eventHeader = EventHeader.Read(ref reader); var parser = new UserVarEventParser(); var @event = (UserVarEvent)parser.ParseEvent(eventHeader, ref reader); diff --git a/tests/MySqlCdc.Tests/Providers/MySql/PreviousGtidsEventParserTests.cs b/tests/MySqlCdc.Tests/Providers/MySql/PreviousGtidsEventParserTests.cs index 076480d..3d88572 100644 --- a/tests/MySqlCdc.Tests/Providers/MySql/PreviousGtidsEventParserTests.cs +++ b/tests/MySqlCdc.Tests/Providers/MySql/PreviousGtidsEventParserTests.cs @@ -31,6 +31,6 @@ public void Test_ParsePreviousGtidsEvent_ReturnsGtidSet() private EventHeader CreateEventHeader() { var reader = new PacketReader(Payload); - return new EventHeader(ref reader); + return EventHeader.Read(ref reader); } } \ No newline at end of file diff --git a/tests/MySqlCdc.Tests/Providers/MySql/XaPrepareEventParserTests.cs b/tests/MySqlCdc.Tests/Providers/MySql/XaPrepareEventParserTests.cs index 5712ea9..eeb366a 100644 --- a/tests/MySqlCdc.Tests/Providers/MySql/XaPrepareEventParserTests.cs +++ b/tests/MySqlCdc.Tests/Providers/MySql/XaPrepareEventParserTests.cs @@ -27,6 +27,6 @@ public void Test_ParseXaPrepareEvent_ReturnsEvent() private EventHeader CreateEventHeader() { var reader = new PacketReader(Payload); - return new EventHeader(ref reader); + return EventHeader.Read(ref reader); } } \ No newline at end of file