Java Code Examples for com.taobao.tddl.dbsync.binlog.LogBuffer#getString()
The following examples show how to use
com.taobao.tddl.dbsync.binlog.LogBuffer#getString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IncidentLogEvent.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
public IncidentLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header); final int commonHeaderLen = descriptionEvent.commonHeaderLen; final int postHeaderLen = descriptionEvent.postHeaderLen[header.type - 1]; buffer.position(commonHeaderLen); final int incidentNumber = buffer.getUint16(); if (incidentNumber >= INCIDENT_COUNT || incidentNumber <= INCIDENT_NONE) { // If the incident is not recognized, this binlog event is // invalid. If we set incident_number to INCIDENT_NONE, the // invalidity will be detected by is_valid(). incident = INCIDENT_NONE; message = null; return; } incident = incidentNumber; buffer.position(commonHeaderLen + postHeaderLen); message = buffer.getString(); }
Example 2
Source File: IncidentLogEvent.java From canal with Apache License 2.0 | 6 votes |
public IncidentLogEvent(LogHeader header, LogBuffer buffer, FormatDescriptionLogEvent descriptionEvent){ super(header); final int commonHeaderLen = descriptionEvent.commonHeaderLen; final int postHeaderLen = descriptionEvent.postHeaderLen[header.type - 1]; buffer.position(commonHeaderLen); final int incidentNumber = buffer.getUint16(); if (incidentNumber >= INCIDENT_COUNT || incidentNumber <= INCIDENT_NONE) { // If the incident is not recognized, this binlog event is // invalid. If we set incident_number to INCIDENT_NONE, the // invalidity will be detected by is_valid(). incident = INCIDENT_NONE; message = null; return; } incident = incidentNumber; buffer.position(commonHeaderLen + postHeaderLen); message = buffer.getString(); }
Example 3
Source File: LoadLogEvent.java From canal-1.1.3 with Apache License 2.0 | 4 votes |
/** * @see mysql-5.1.60/sql/log_event.cc - Load_log_event::copy_log_event */ protected final void copyLogEvent(LogBuffer buffer, final int bodyOffset, FormatDescriptionLogEvent descriptionEvent) { /* this is the beginning of the post-header */ buffer.position(descriptionEvent.commonHeaderLen + L_EXEC_TIME_OFFSET); execTime = buffer.getUint32(); // L_EXEC_TIME_OFFSET skipLines = (int) buffer.getUint32(); // L_SKIP_LINES_OFFSET final int tableNameLen = buffer.getUint8(); // L_TBL_LEN_OFFSET final int dbLen = buffer.getUint8(); // L_DB_LEN_OFFSET numFields = (int) buffer.getUint32(); // L_NUM_FIELDS_OFFSET buffer.position(bodyOffset); /* * Sql_ex.init() on success returns the pointer to the first byte after * the sql_ex structure, which is the start of field lengths array. */ if (header.type != LOAD_EVENT /* use_new_format */) { /* * The code below assumes that buf will not disappear from under our * feet during the lifetime of the event. This assumption holds true * in the slave thread if the log is in new format, but is not the * case when we have old format because we will be reusing net * buffer to read the actual file before we write out the * Create_file event. */ fieldTerm = buffer.getString(); enclosed = buffer.getString(); lineTerm = buffer.getString(); lineStart = buffer.getString(); escaped = buffer.getString(); optFlags = buffer.getInt8(); emptyFlags = 0; } else { fieldTerm = buffer.getFixString(1); enclosed = buffer.getFixString(1); lineTerm = buffer.getFixString(1); lineStart = buffer.getFixString(1); escaped = buffer.getFixString(1); optFlags = buffer.getUint8(); emptyFlags = buffer.getUint8(); if ((emptyFlags & FIELD_TERM_EMPTY) != 0) fieldTerm = null; if ((emptyFlags & ENCLOSED_EMPTY) != 0) enclosed = null; if ((emptyFlags & LINE_TERM_EMPTY) != 0) lineTerm = null; if ((emptyFlags & LINE_START_EMPTY) != 0) lineStart = null; if ((emptyFlags & ESCAPED_EMPTY) != 0) escaped = null; } final int fieldLenPos = buffer.position(); buffer.forward(numFields); fields = new String[numFields]; for (int i = 0; i < numFields; i++) { final int fieldLen = buffer.getUint8(fieldLenPos + i); fields[i] = buffer.getFixString(fieldLen + 1); } table = buffer.getFixString(tableNameLen + 1); db = buffer.getFixString(dbLen + 1); // null termination is accomplished by the caller final int from = buffer.position(); final int end = from + buffer.limit(); int found = from; for (; (found < end) && buffer.getInt8(found) != '\0'; found++) /* empty loop */; fname = buffer.getString(found); buffer.forward(1); // The + 1 is for \0 terminating fname }
Example 4
Source File: LoadLogEvent.java From canal with Apache License 2.0 | 4 votes |
/** * @see mysql-5.1.60/sql/log_event.cc - Load_log_event::copy_log_event */ protected final void copyLogEvent(LogBuffer buffer, final int bodyOffset, FormatDescriptionLogEvent descriptionEvent) { /* this is the beginning of the post-header */ buffer.position(descriptionEvent.commonHeaderLen + L_EXEC_TIME_OFFSET); execTime = buffer.getUint32(); // L_EXEC_TIME_OFFSET skipLines = (int) buffer.getUint32(); // L_SKIP_LINES_OFFSET final int tableNameLen = buffer.getUint8(); // L_TBL_LEN_OFFSET final int dbLen = buffer.getUint8(); // L_DB_LEN_OFFSET numFields = (int) buffer.getUint32(); // L_NUM_FIELDS_OFFSET buffer.position(bodyOffset); /* * Sql_ex.init() on success returns the pointer to the first byte after * the sql_ex structure, which is the start of field lengths array. */ if (header.type != LOAD_EVENT /* use_new_format */) { /* * The code below assumes that buf will not disappear from under our * feet during the lifetime of the event. This assumption holds true * in the slave thread if the log is in new format, but is not the * case when we have old format because we will be reusing net * buffer to read the actual file before we write out the * Create_file event. */ fieldTerm = buffer.getString(); enclosed = buffer.getString(); lineTerm = buffer.getString(); lineStart = buffer.getString(); escaped = buffer.getString(); optFlags = buffer.getInt8(); emptyFlags = 0; } else { fieldTerm = buffer.getFixString(1); enclosed = buffer.getFixString(1); lineTerm = buffer.getFixString(1); lineStart = buffer.getFixString(1); escaped = buffer.getFixString(1); optFlags = buffer.getUint8(); emptyFlags = buffer.getUint8(); if ((emptyFlags & FIELD_TERM_EMPTY) != 0) fieldTerm = null; if ((emptyFlags & ENCLOSED_EMPTY) != 0) enclosed = null; if ((emptyFlags & LINE_TERM_EMPTY) != 0) lineTerm = null; if ((emptyFlags & LINE_START_EMPTY) != 0) lineStart = null; if ((emptyFlags & ESCAPED_EMPTY) != 0) escaped = null; } final int fieldLenPos = buffer.position(); buffer.forward(numFields); fields = new String[numFields]; for (int i = 0; i < numFields; i++) { final int fieldLen = buffer.getUint8(fieldLenPos + i); fields[i] = buffer.getFixString(fieldLen + 1); } table = buffer.getFixString(tableNameLen + 1); db = buffer.getFixString(dbLen + 1); // null termination is accomplished by the caller final int from = buffer.position(); final int end = from + buffer.limit(); int found = from; for (; (found < end) && buffer.getInt8(found) != '\0'; found++) /* empty loop */; fname = buffer.getString(found); buffer.forward(1); // The + 1 is for \0 terminating fname }