List of usage examples for io.netty.buffer ByteBuf readByte
public abstract byte readByte();
From source file:com.tesora.dve.db.mysql.libmy.MyOKResponse.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { cb.readByte(); // field count - always 0 affectedRows = MysqlAPIUtils.getLengthCodedLong(cb); insertId = MysqlAPIUtils.getLengthCodedLong(cb); serverStatus = cb.readUnsignedShort(); warningCount = cb.readUnsignedShort(); if (cb.isReadable()) message = MysqlAPIUtils.readBytesAsString(cb, CharsetUtil.UTF_8); }
From source file:com.tesora.dve.db.mysql.libmy.MyOKResponse.java
License:Open Source License
public static long getAffectedRows(ByteBuf cb) { cb.readByte(); return MysqlAPIUtils.getLengthCodedLong(cb); }
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 {// w w w . java 2s . com parseValues.initialDatabase = ""; } return parseValues; }
From source file:com.tesora.dve.db.mysql.portal.protocol.MSPComStmtExecuteRequestMessage.java
License:Open Source License
@Override protected ParsedData unmarshall(ByteBuf source) { ParsedData parseValues = new ParsedData(); source.skipBytes(1);//skip the type identifier. parseValues.statementID = source.readUnsignedInt(); parseValues.flags = source.readByte(); parseValues.iterationCount = source.readUnsignedInt(); parseValues.metadataOffset = source.readerIndex(); //we don't actually unmarshall the metadata and values here, since we don't know how many parameters there are. parseValues.metadata = null;/*from ww w .ja v a 2 s. c o m*/ parseValues.values = null; return parseValues; }
From source file:com.tesora.dve.db.mysql.portal.protocol.MSPComStmtExecuteRequestMessage.java
License:Open Source License
public void readParameterMetadata(MyPreparedStatement<String> pStmt) throws PEException { //TODO: this belongs in unmarshall, but requires knowledge about the expected number of parameters, provided by a previous prepare response. ParsedData cachedParse = readState(); ByteBuf backingData = readBuffer();/*from w w w . j a v a 2 s . c o m*/ int lengthOfMetadata = backingData.readableBytes() - cachedParse.metadataOffset; ByteBuf in = backingData.slice(cachedParse.metadataOffset, lengthOfMetadata).order(ByteOrder.LITTLE_ENDIAN); if (pStmt.getNumParams() > 0) { int nullBitmapLength = (pStmt.getNumParams() + 7) / 8; MyNullBitmap nullBitmap = new MyNullBitmap(MysqlAPIUtils.readBytes(in, nullBitmapLength), pStmt.getNumParams(), MyNullBitmap.BitmapType.EXECUTE_REQUEST); if (in.readByte() == 1) { // this is new params bound flag; only // =1 on first stmt_execute pStmt.clearParameters(); for (int i = 0; i < pStmt.getNumParams(); i++) { pStmt.addParameter(new MyParameter(MyFieldType.fromByte(in.readByte()))); in.skipBytes(1); } } for (int paramNum = 1; paramNum <= pStmt.getNumParams(); paramNum++) { MyParameter parameter = pStmt.getParameter(paramNum); if (nullBitmap.getBit(paramNum)) { parameter.setValue(null); } else { //TODO - may need to figure out how to get the proper flags and length into this call parameter.setValue(DBTypeBasedUtils.getMysqlTypeFunc(parameter.getType()).readObject(in)); } } } }
From source file:com.tesora.dve.db.mysql.portal.protocol.MSPServerGreetingRequestMessage.java
License:Open Source License
@Override public MSPServerGreetingRequestMessage newPrototype(ByteBuf source) { final byte messageType = source.readByte(); source = source.slice();/* ww w. j a v a 2s .c om*/ return new MSPServerGreetingRequestMessage(source); }
From source file:com.tesora.dve.db.mysql.portal.protocol.MysqlClientAuthenticationHandler.java
License:Open Source License
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out, boolean isLastBytes) throws Exception { ByteBuf leBuf = in.order(ByteOrder.LITTLE_ENDIAN); leBuf.markReaderIndex();//from w w w. ja v a 2 s . c om boolean messageProcessed = false; try { if (leBuf.readableBytes() > MESSAGE_HEADER_LEN) { int payloadLen = leBuf.readMedium(); leBuf.readByte(); // seq if (leBuf.readableBytes() >= payloadLen) { ByteBuf payload = leBuf.slice(leBuf.readerIndex(), payloadLen).order(ByteOrder.LITTLE_ENDIAN); Byte protocolVersion = leBuf.readByte(); leBuf.skipBytes(payloadLen - 1); messageProcessed = true; if (state == AuthenticationState.AWAIT_GREETING) processGreeting(ctx, payload, protocolVersion); else processAcknowlegement(ctx, payload); } } } catch (Throwable t) { enterState(AuthenticationState.FAILURE); log.warn("Unexpected problem on outbound mysql connection.", t); throw t; } finally { if (!messageProcessed) leBuf.resetReaderIndex(); if (isLastBytes && (state == AuthenticationState.AWAIT_ACKNOWLEGEMENT || state == AuthenticationState.AWAIT_GREETING)) { //we are waiting for handshake packets from mysql, but no more packets will ever arrive. release blocked callers. Channel channel = ctx.channel(); SocketAddress addr = (channel == null ? null : channel.remoteAddress()); log.warn("Socket closed in middle of authentication handshake on socket " + addr); enterState(AuthenticationState.FAILURE); } } }
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();// w ww . j a 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();/* w w w. j av a2s . com*/ serverVersion = MysqlAPIUtils.readBytesAsString(cb, ST_SERVER_VER_LEN, CharsetUtil.UTF_8); createTime = cb.readUnsignedInt(); 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.MyIntvarLogEvent.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { variableType = cb.readByte(); variableValue = UnsignedLong.valueOf(cb.readLong()); }