Example usage for io.netty.buffer ByteBuf readInt

List of usage examples for io.netty.buffer ByteBuf readInt

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf readInt.

Prototype

public abstract int readInt();

Source Link

Document

Gets a 32-bit integer at the current readerIndex and increases the readerIndex by 4 in this buffer.

Usage

From source file:com.tesora.dve.db.mysql.libmy.MyPrepareOKResponse.java

License:Open Source License

@Override
public void unmarshallMessage(ByteBuf cb) {
    cb.skipBytes(1);//from  w ww  .j a va  2s  .  com
    stmtId = cb.readInt();
    numColumns = cb.readUnsignedShort();
    numParams = cb.readUnsignedShort();
    cb.skipBytes(1);
    warningCount = cb.readShort();
}

From source file:com.tesora.dve.db.mysql.portal.protocol.MSPAuthenticateV10MessageMessage.java

License:Open Source License

@Override
protected ParsedData unmarshall(ByteBuf source) {
    ParsedData parseValues = new ParsedData();
    parseValues.caps = new ClientCapabilities(source.readUnsignedInt());
    parseValues.maxPacketSize = source.readInt();
    parseValues.charsetID = source.readByte();

    source.skipBytes(23); // login request has a 23 byte filler
    parseValues.username = source.readSlice(source.bytesBefore((byte) 0)).toString(CharsetUtil.UTF_8);
    source.skipBytes(1); // skip the NULL terminator
    byte passwordLength = source.readByte();
    parseValues.password = source.readSlice(passwordLength).toString(CharsetUtil.ISO_8859_1);

    // if the clientCapabilities flag has the CLIENT_CONNECT_WITH_DB bit set,
    // then this message contains an initial database to connect to
    if (parseValues.caps.connectWithDB()) {
        parseValues.initialDatabase = source.readSlice(source.bytesBefore((byte) 0))
                .toString(CharsetUtil.UTF_8);
        source.skipBytes(1); // skip the NULL terminator
    } else {/* ww  w.  j a v  a 2s . c om*/
        parseValues.initialDatabase = "";
    }
    return parseValues;
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyAppendBlockLogEvent.java

License:Open Source License

@Override
public void unmarshallMessage(ByteBuf cb) {
    fileId = cb.readInt();
    dataBlock = Unpooled.buffer(cb.readableBytes());
    dataBlock.writeBytes(cb);
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyComBinLogDumpRequest.java

License:Open Source License

@Override
public void unmarshallMessage(ByteBuf cb) {
    binlogPosition = cb.readUnsignedInt();
    cb.skipBytes(2);//from ww  w.j av  a  2s  . co m
    slaveServerID = cb.readInt();
    if (cb.readableBytes() > 0) {
        binlogFileName = cb.readSlice(cb.readableBytes()).toString(CharsetUtil.UTF_8);
    }
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyComRegisterSlaveRequest.java

License:Open Source License

@Override
public void unmarshallMessage(ByteBuf cb) {
    slaveServerId = cb.readInt();
    reportHost = MysqlAPIUtils.getLengthCodedString(cb);
    reportUser = MysqlAPIUtils.getLengthCodedString(cb);
    reportPassword = MysqlAPIUtils.getLengthCodedString(cb);
    reportPort = cb.readShort();/*from ww  w  .  java  2 s  .c  o  m*/
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyCreateFileLogEvent.java

License:Open Source License

@Override
public void unmarshallMessage(ByteBuf cb) {
    threadId = cb.readInt();
    // TODO: need to parse out the variable part of the data
    variableData = Unpooled.buffer(cb.readableBytes());
    variableData.writeBytes(cb);/*from ww  w . j av  a  2  s.  c  o  m*/
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyDeleteFileLogEvent.java

License:Open Source License

@Override
public void unmarshallMessage(ByteBuf cb) {
    fileId = cb.readInt();
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyExecuteLoadLogEvent.java

License:Open Source License

@Override
public void unmarshallMessage(ByteBuf cb) throws PEException {
    threadId = cb.readInt();
    time = cb.readInt();/*from   w ww .ja v a 2  s . c om*/
    dbLen = cb.readByte();
    errorCode = cb.readShort();
    statusBlockLen = cb.readShort();
    fileId = cb.readInt();
    startPos = cb.readInt();
    endPos = cb.readInt();
    duplicateFlag = cb.readByte();
    // really we should check if replication version >=4 or else this is wrong
    statusVars.parseStatusVariables(cb, statusBlockLen);

    dbName = MysqlAPIUtils.readBytesAsString(cb, dbLen, CharsetUtil.UTF_8);
    cb.skipBytes(1); //for trailing 0
    query = Unpooled.buffer(cb.readableBytes());
    query.writeBytes(cb);
    origQuery = query.toString(CharsetUtil.UTF_8);
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyLoadLogEvent.java

License:Open Source License

@Override
public void unmarshallMessage(ByteBuf cb) {
    threadId = cb.readInt();
    time = cb.readInt();/*from   w  ww  .  j a va2  s  .  c  om*/
    ignoreLines = cb.readInt();
    tableLen = cb.readByte();
    dbLen = cb.readByte();
    columns = cb.readInt();
    // TODO: need to parse out the variable part of the data
    variableData = Unpooled.buffer(cb.readableBytes());
    variableData.writeBytes(cb);
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyStatusVariables.java

License:Open Source License

public void parseStatusVariables(ByteBuf cb, int svLen) throws PEException {
    if (svLen > 0) {
        ByteBuf statsVarsBuf = cb.readBytes(svLen);
        while (statsVarsBuf.isReadable()) {
            byte code = statsVarsBuf.readByte();
            MyQueryEventCode mqec = MyQueryEventCode.fromByte(code);
            if (mqec == null) {
                throw new PEException("Replication could not decode query event code: '" + code + "' (0x"
                        + Integer.toHexString(code) + ")");
            }/*  w w  w  . j  av a  2  s. c om*/

            switch (mqec) {
            case Q_FLAGS2_CODE:
                int flags = statsVarsBuf.readInt();
                suppliedEventCodes.add(new QueryFlags2Event(flags));
                break;

            case Q_SQL_MODE_CODE:
                long sqlMode = statsVarsBuf.readLong();
                suppliedEventCodes.add(new QuerySQLModeEvent(sqlMode));
                break;

            case Q_CATALOG_CODE: {
                byte len = statsVarsBuf.readByte();
                String catalog = MysqlAPIUtils.readBytesAsString(statsVarsBuf, len, CharsetUtil.UTF_8);
                statsVarsBuf.readByte(); // null terminated byte

                suppliedEventCodes.add(new QueryCatalogEvent(catalog));
                break;
            }
            case Q_AUTO_INCREMENT:
                int autoIncrementIncrement = statsVarsBuf.readUnsignedShort();
                int autoIncrementOffset = statsVarsBuf.readUnsignedShort();

                suppliedEventCodes
                        .add(new QueryAutoIncrementEvent(autoIncrementIncrement, autoIncrementOffset));
                break;

            case Q_CHARSET_CODE:
                int charSetClient = statsVarsBuf.readUnsignedShort();
                int collationConnection = statsVarsBuf.readUnsignedShort();
                int collationServer = statsVarsBuf.readUnsignedShort();

                suppliedEventCodes
                        .add(new QueryCharSetCodeEvent(charSetClient, collationConnection, collationServer));
                break;

            case Q_TIME_ZONE_CODE: {
                byte len = statsVarsBuf.readByte();
                String timeZone = MysqlAPIUtils.readBytesAsString(statsVarsBuf, len, CharsetUtil.UTF_8);

                suppliedEventCodes.add(new QueryTimeZoneCodeEvent(timeZone));
                break;
            }
            case Q_CATALOG_NZ_CODE: {
                byte catalogLen = statsVarsBuf.readByte();
                String catalog = MysqlAPIUtils.readBytesAsString(statsVarsBuf, catalogLen, CharsetUtil.UTF_8);

                suppliedEventCodes.add(new QueryCatalogNZEvent(catalog));
                break;
            }
            case Q_LC_TIME_NAMES_CODE:
                short monthDayNames = statsVarsBuf.readShort();

                suppliedEventCodes.add(new QueryTimeNamesEvent(monthDayNames));
                break;

            case Q_CHARSET_DATABASE_CODE:
                short collationDatabase = statsVarsBuf.readShort();

                suppliedEventCodes.add(new QueryCollationDatabaseEvent(collationDatabase));
                break;

            case Q_TABLE_MAP_FOR_UPDATE_CODE:
                long tableMapForUpdate = statsVarsBuf.readLong();

                suppliedEventCodes.add(new QueryTableMapEvent(tableMapForUpdate));
                break;

            case Q_MASTER_DATA_WRITTEN_CODE:
                int originalLength = statsVarsBuf.readInt();

                suppliedEventCodes.add(new QueryMasterDataWrittenEvent(originalLength));
                break;

            case Q_INVOKER:
                int userLen = statsVarsBuf.readByte();
                String user = MysqlAPIUtils.readBytesAsString(statsVarsBuf, userLen, CharsetUtil.UTF_8);
                int hostLen = statsVarsBuf.readByte();
                String host = MysqlAPIUtils.readBytesAsString(statsVarsBuf, hostLen, CharsetUtil.UTF_8);

                suppliedEventCodes.add(new QueryInvokerEvent(user, host));
                break;

            case Q_UPDATED_DB_NAMES:
                List<String> dbNames = new ArrayList<String>();
                int numDbs = statsVarsBuf.readByte();
                if (numDbs > 0) {
                    for (int i = 0; i < numDbs; i++) {
                        dbNames.add(statsVarsBuf.readSlice(statsVarsBuf.bytesBefore((byte) 0))
                                .toString(CharsetUtil.UTF_8));
                        statsVarsBuf.readByte(); //read null byte
                    }
                }
                suppliedEventCodes.add(new QueryUpdatedDBNamesEvent(dbNames));
                break;

            case Q_MICROSECONDS:
                int microseconds = statsVarsBuf.readMedium();

                suppliedEventCodes.add(new QueryMicrosecondsEvent(microseconds));
                break;

            case Q_HRNOW:
                //TODO: this was apparently added for MariaDB, but I can't find a lot of info on it. skip for now.
                suppliedEventCodes.add(new QueryMicrosecondsEvent(statsVarsBuf.readUnsignedMedium()));
                break;

            default:
                throw new PEException("Replication encountered an unknown query event code: '" + code + "' (0x"
                        + Integer.toHexString(code) + ")");
            }
        }
    }
}