Skip to content

Commit e8dad42

Browse files
Group the unpack when reading the packet
1 parent b7d63bc commit e8dad42

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

pymysqlreplication/packet.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,25 @@ def __init__(self, from_packet, table_map, ctl_connection, use_checksum, allowed
5454
# Used when we want to override a value in the data buffer
5555
self.__data_buffer = b''
5656

57-
# Ok Value
5857
self.packet = from_packet
59-
self.packet.advance(1)
6058
self.charset = ctl_connection.charset
6159

60+
# OK value
61+
# timestamp
62+
# event_type
63+
# server_id
64+
# log_pos
65+
# flags
66+
unpack = struct.unpack('<cIcIIIH', self.packet.read(20))
67+
6268
# Header
63-
self.timestamp = struct.unpack('<I', self.packet.read(4))[0]
64-
self.event_type = byte2int(self.packet.read(1))
65-
self.server_id = struct.unpack('<I', self.packet.read(4))[0]
66-
self.event_size = struct.unpack('<I', self.packet.read(4))[0]
69+
self.timestamp = unpack[1]
70+
self.event_type = byte2int(unpack[2])
71+
self.server_id = unpack[3]
72+
self.event_size = unpack[4]
6773
# position of the next event
68-
self.log_pos = struct.unpack('<I', self.packet.read(4))[0]
69-
self.flags = struct.unpack('<H', self.packet.read(2))[0]
74+
self.log_pos = unpack[5]
75+
self.flags = unpack[6]
7076

7177
# MySQL 5.6 and more if binlog-checksum = CRC32
7278
if use_checksum:

0 commit comments

Comments
 (0)