protected internal override void DecodeBody(ref SequenceReader <byte> reader, object context) { TableID = reader.ReadLong(6); reader.TryReadLittleEndian(out short flags); RowsEventFlags = (RowsEventFlags)flags; reader.TryReadLittleEndian(out short extraDataLen); reader.Advance(extraDataLen - 2); ReadIncludedColumns(ref reader); TableMapEvent tableMap = null; if (context is ReplicationState repState) { if (repState.TableMap.TryGetValue(TableID, out tableMap)) { TableMap = tableMap; } } if (tableMap == null) { throw new Exception($"The table's metadata was not found: {TableID}."); } var columnCount = GetIncludedColumnCount(IncludedColumns); RebuildReaderAsCRC(ref reader); ReadData(ref reader, IncludedColumns, tableMap, columnCount); }
protected internal override void DecodeBody(ref SequenceReader <byte> reader, object context) { TableID = reader.ReadLong(6); reader.TryReadLittleEndian(out short flags); reader.TryReadLittleEndian(out short extraDataLen); reader.Advance(extraDataLen); IncludedColumnsBeforeUpdate = reader.ReadBitArray((int)reader.ReadLengthEncodedInteger()); IncludedColumns = reader.ReadBitArray((int)reader.ReadLengthEncodedInteger()); TableMapEvent tableMap = null; if (context is ReplicationState repState) { repState.TableMap.TryGetValue(TableID, out tableMap); } if (tableMap == null) { throw new Exception($"The table's metadata was not found: {TableID}."); } Rows = ReadUpdatedRows(ref reader, tableMap, IncludedColumnsBeforeUpdate, IncludedColumns); }
private RowSet ReadUpdatedRows(ref SequenceReader <byte> reader, TableMapEvent tableMap, BitArray includedColumnsBeforeUpdate, BitArray includedColumns, int columnCount) { var columnCountBeforeUpdate = GetIncludedColumnCount(IncludedColumnsBeforeUpdate); var rows = new List <object[]>(); var columns = GetColumnNames(tableMap, includedColumnsBeforeUpdate, columnCount); while (reader.Remaining > 0) { var oldCellValues = ReadRow(ref reader, tableMap, includedColumnsBeforeUpdate, columnCountBeforeUpdate); var newCellValues = ReadRow(ref reader, tableMap, includedColumnsBeforeUpdate, columnCount); var cellCount = Math.Min(oldCellValues.Length, newCellValues.Length); var cells = new object[cellCount]; for (var i = 0; i < cellCount; i++) { cells[i] = new CellValue { OldValue = oldCellValues[i], NewValue = newCellValues[i] }; } rows.Add(cells); } return(new RowSet { ColumnNames = columns, Rows = rows }); }
protected List <object[]> ReadRows(ref SequenceReader <byte> reader, TableMapEvent table, BitArray includedColumns, int columnCount) { var rows = new List <object[]>(); while (reader.Remaining > 0) { rows.Add(ReadRow(ref reader, table, includedColumns, columnCount)); } return(rows); }
protected RowSet ReadRows(ref SequenceReader <byte> reader, TableMapEvent table, BitArray includedColumns, int columnCount) { var rows = new List <object[]>(); var columns = GetColumnNames(table, includedColumns, columnCount); while (reader.Remaining > 0) { rows.Add(ReadRow(ref reader, table, includedColumns, columnCount)); } return(new RowSet { Rows = rows, ColumnNames = columns }); }
protected IReadOnlyList <string> GetColumnNames(TableMapEvent table, BitArray includedColumns, int columnCount) { var columns = new List <string>(columnCount); var columnNames = table.Metadata.ColumnNames; if (columnNames != null && columnNames.Count > 0) { for (var i = 0; i < includedColumns.Count; i++) { if (!includedColumns.Get(i)) { continue; } columns.Add(columnNames[i]); } } return(columns); }
protected object[] ReadRow(ref SequenceReader <byte> reader, TableMapEvent table, BitArray includedColumns, int columnCount) { var cells = new object[columnCount]; var nullColumns = reader.ReadBitArray(columnCount, true); var columnTypes = table.ColumnTypes; var columnMetadata = table.ColumnMetadata; for (int i = 0, numberOfSkippedColumns = 0; i < columnTypes.Length; i++) { if (!includedColumns.Get(i)) { numberOfSkippedColumns++; continue; } int index = i - numberOfSkippedColumns; if (nullColumns.Get(index)) { continue; } var typeCode = columnTypes[i]; var meta = columnMetadata[i]; var length = 0; var columnType = (ColumnType)typeCode; if (columnType == ColumnType.STRING) { if (meta >= 256) { int meta0 = meta >> 8, meta1 = meta & 0xFF; if ((meta0 & 0x30) != 0x30) { typeCode = (byte)(meta0 | 0x30); columnType = (ColumnType)typeCode; length = meta1 | (((meta0 & 0x30) ^ 0x30) << 4); } else { // mysql-5.6.24 sql/rpl_utility.h enum_field_types (line 278) if (meta0 == (int)ColumnType.ENUM || meta0 == (int)ColumnType.SET) { typeCode = (byte)meta0; columnType = (ColumnType)typeCode; } length = meta1; } } else { length = meta; } } cells[index] = ReadCell(ref reader, columnType, meta, length); } return(cells); }
protected virtual void ReadData(ref SequenceReader <byte> reader, BitArray includedColumns, TableMapEvent tableMap, int columnCount) { RowSet = ReadRows(ref reader, tableMap, IncludedColumns, columnCount); }
private List <Tuple <object[], object[]> > ReadUpdatedRows(ref SequenceReader <byte> reader, TableMapEvent tableMap, BitArray includedColumnsBeforeUpdate, BitArray includedColumns) { var columnCountBeforeUpdate = GetIncludedColumnCount(IncludedColumnsBeforeUpdate); var columnCount = GetIncludedColumnCount(IncludedColumns); var rows = new List <Tuple <object[], object[]> >(); while (reader.Remaining > 0) { rows.Add(Tuple.Create( ReadRow(ref reader, tableMap, includedColumnsBeforeUpdate, columnCountBeforeUpdate), ReadRow(ref reader, tableMap, includedColumns, columnCount)) ); } return(rows); }
protected override void ReadData(ref SequenceReader <byte> reader, BitArray includedColumns, TableMapEvent tableMap, int columnCount) { RowSet = ReadUpdatedRows(ref reader, tableMap, IncludedColumnsBeforeUpdate, includedColumns, columnCount); }