List of usage examples for io.netty.buffer ByteBuf readShort
public abstract short readShort();
From source file:com.tesora.dve.db.mysql.libmy.MyFieldPktResponse.java
License:Open Source License
private void unpackTypeInfo(ByteBuf cb) { int remainingPayload = cb.readableBytes(); int charsetOffset = remainingPayload + CHARSET_OFFSET_RELATIVE_TO_EOF; cb.skipBytes(charsetOffset);//from w ww . j a v a2s .com charset = cb.readByte(); cb.skipBytes(1); column_length = cb.readInt();//TODO: this should be an unsigned int. Will cause problems if length exceeds Integer.MAX_VALUE. column_type = MyFieldType.fromByte(cb.readByte()); flags = cb.readShort(); scale = cb.readByte(); //plus two pad bytes of zero }
From source file:com.tesora.dve.db.mysql.libmy.MyHandshakeErrorResponse.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { cb.readByte(); setErrorNumber(cb.readShort()); setErrorMsg(cb.slice().toString(charset)); }
From source file:com.tesora.dve.db.mysql.libmy.MyHandshakeV10.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { protocolVersion = cb.readByte();//from w ww. j av a 2 s. c o m serverVersion = cb.readSlice(cb.bytesBefore((byte) 0)).toString(CharsetUtil.UTF_8); cb.skipBytes(1); // skip the NULL terminator threadID = cb.readInt(); scrambleBuffer1st = MysqlAPIUtils.readBytesAsString(cb, 8, CharsetUtil.ISO_8859_1); cb.skipBytes(1); long sc1 = cb.readUnsignedShort(); serverCharset = cb.readByte(); serverStatus = cb.readShort(); long sc2 = Long.rotateLeft(cb.readUnsignedShort(), 16); setServerCapabilities(sc1 + sc2); scrambleBufferSize = new Integer(cb.readByte()); cb.skipBytes(10); //unused bytes scrambleBuffer2nd = cb.readSlice(cb.bytesBefore((byte) 0)).toString(CharsetUtil.ISO_8859_1); cb.skipBytes(1); if ((serverCapabilitiesasLong & ClientCapabilities.CLIENT_PLUGIN_AUTH) == ClientCapabilities.CLIENT_PLUGIN_AUTH) { plugInProvidedData = cb.readSlice(cb.bytesBefore((byte) 0)).toString(CharsetUtil.UTF_8); } }
From source file:com.tesora.dve.db.mysql.libmy.MyPrepareOKResponse.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { cb.skipBytes(1);/*w ww .j av a2 s .co m*/ stmtId = cb.readInt(); numColumns = cb.readUnsignedShort(); numParams = cb.readUnsignedShort(); cb.skipBytes(1); warningCount = cb.readShort(); }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyComRegisterSlaveRequest.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { slaveServerId = cb.readInt();// ww w.ja v a2 s . com reportHost = MysqlAPIUtils.getLengthCodedString(cb); reportUser = MysqlAPIUtils.getLengthCodedString(cb); reportPassword = MysqlAPIUtils.getLengthCodedString(cb); reportPort = cb.readShort(); }
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();//from w w w . ja v a 2s . c o m time = cb.readInt(); 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.MyFormatDescriptionLogEvent.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { binaryLogVersion = cb.readShort(); serverVersion = MysqlAPIUtils.readBytesAsString(cb, ST_SERVER_VER_LEN, CharsetUtil.UTF_8); createTime = cb.readUnsignedInt();/*ww w . j av a2 s . c o m*/ eventTypeLength = cb.readUnsignedByte(); int numberOfEntries = cb.readableBytes() - 1;//string is null terminated. switch (MyBinLogVerType.fromByte((byte) binaryLogVersion)) { case MySQL_5_0: for (int i = 1; i <= numberOfEntries; i++) { eventTypeValues.put(MyLogEventType.fromByte((byte) i), cb.readByte()); } cb.skipBytes(1);//throw out EOF break; default: // TODO throw???? logger.error("Cannot process binary log messages that are not for MySQL 5.0"); } }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyReplEvent.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) throws PEException { //assumes the provided buffer is already scoped to payload boundary. rawPayload = cb.slice().copy();/*from www .j a v a 2 s. com*/ // 19 bytes for the common header commonHdr = new MyReplEventCommonHeader(); commonHdr.setTimestamp(cb.readUnsignedInt()); commonHdr.setType(cb.readByte()); commonHdr.setServerId(cb.readUnsignedInt()); commonHdr.setTotalSize(cb.readUnsignedInt()); commonHdr.setMasterLogPosition(cb.readUnsignedInt()); commonHdr.setFlags(cb.readShort()); // unmarshall message based on common header type if (logger.isDebugEnabled()) logger.debug("Unmarshalling event of type: " + MyLogEventType.fromByte(commonHdr.getType()).name()); levp = MyLogEventPacket.MySqlLogEventFactory.newInstance(MyLogEventType.fromByte(commonHdr.getType()), commonHdr); levp.unmarshallMessage(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) + ")"); }//from ww w . j ava 2 s . co m 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) + ")"); } } } }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyTableMapLogEvent.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { tableId = cb.readInt();// www .j a va 2 s. c om reserved = cb.readShort(); // TODO: need to parse out the variable part of the data variableData = Unpooled.buffer(cb.readableBytes()); variableData.writeBytes(cb); }