Learning some details of the binary log format can reveal a lot about the replication internals. The code that deals with the binary logging is found in sql/log_event.h and sql/log_event.cc.
The binary log starts with a 4-byte magic number, which is set in the following line of sql/log_event.h:
#define BINLOG_MAGIC "\xfe\x62\x69\x6e"
The magic number is used by the code that reads the binary log for a quick sanity check to make sure a valid binary log is being used. It is also used by the Unix file utility, which identifies file types.
The magic number is followed by a sequence of event entries. All
events have a common header with the fields listed in Table 12-2 in
sequential order. The second field represents the type code of the
event, and is explained in Table 12-3. All of the
integers in the header are stored in the little-endian format (low byte
first). The header is written out by
Log_event::write_header( ) in
Table 12-2. Binary log event header
Timestamp of the event. Number of seconds since the
start of the year 1970 as returned by the
The type code of the event. The values and the meaning of the code are explained in Table 12-3.
Server ID. Uniquely identifies the server among its replication peers. Mainly used for avoiding infinite update loops.
The length of the whole event, including the header, in bytes.
Offset of the event in the log in bytes
Event flags. For details see sql/log_event.h; search ...