Skip to content

Commit 75a2f34

Browse files
committed
Added heartbeat parser and definitions
1 parent c9122a0 commit 75a2f34

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

lib/binlog_event.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ BinlogEvent.prototype._readTableId = function (parser) {
2828
this.tableId = Common.parseUInt48(parser);
2929
};
3030

31+
function Heartbeat(parser) {
32+
BinlogEvent.apply(this, arguments);
33+
this.binlogName = parser.parseString(this.size - 8);
34+
this.position = Common.parseUInt64(parser);
35+
}
36+
util.inherits(Heartbeat, BinlogEvent);
37+
38+
Heartbeat.prototype.dump = function () {
39+
console.log('=== %s ===', this.getTypeName());
40+
console.log('Event size: %d', this.size);
41+
console.log('Position: %d', this.position);
42+
console.log('Current binlog file: %s', this.binlogName);
43+
};
44+
3145
/* Change MySQL bin log file
3246
* Attributes:
3347
* position: Position inside next binlog
@@ -303,6 +317,7 @@ function Unknown() {
303317
util.inherits(Unknown, BinlogEvent);
304318

305319
exports.BinlogEvent = BinlogEvent;
320+
exports.Heartbeat = Heartbeat;
306321
exports.Rotate = Rotate;
307322
exports.Format = Format;
308323
exports.Query = Query;

lib/code_map.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const EventClass = {
4848
FORMAT_DESCRIPTION_EVENT: events.Format,
4949
XID_EVENT: events.Xid,
5050
GTID_LOG_EVENT: events.GtidLog,
51+
HEARTBEAT_LOG_EVENT: events.Heartbeat,
5152

5253
TABLE_MAP_EVENT: events.TableMap,
5354
DELETE_ROWS_EVENT_V1: rowsEvents.DeleteRows,

types/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ export type BaseBinLogEvent = {
106106
useChecksum: boolean;
107107
};
108108

109+
export type BinLogHeartbeatEvent = {
110+
binlogName: string;
111+
position: number;
112+
};
113+
109114
export type BinLogRotationEvent = BaseBinLogEvent & {
110115
binlogName: string;
111116
position: number;
@@ -165,6 +170,7 @@ export type BinLogQueryEvent = BaseBinLogEvent & {
165170

166171
export type BinLogEvent =
167172
| BinLogRotationEvent
173+
| BinLogHeartbeatEvent
168174
| BinLogGTIDLogEvent
169175
| BinLogXidEvent
170176
| BinLogRowEvent

0 commit comments

Comments
 (0)