List of usage examples for io.netty.buffer ByteBuf writeInt
public abstract ByteBuf writeInt(int value);
From source file:com.tesora.dve.db.mysql.libmy.MyHandshakeV10.java
License:Open Source License
@Override public void marshallMessage(ByteBuf cb) { cb.writeByte(protocolVersion);//ww w. j ava 2s.c om cb.writeBytes(getServerVersion().getBytes()); cb.writeZero(1); cb.writeInt(getThreadID()); cb.writeBytes(scrambleBuffer1st.getBytes()); // Salt cb.writeZero(1); cb.writeByte(getServerCapabilities((byte) 0)); cb.writeByte(getServerCapabilities((byte) 1)); cb.writeByte(getServerCharsetId()); cb.writeShort(serverStatus); cb.writeByte(getServerCapabilities((byte) 2)); cb.writeByte(getServerCapabilities((byte) 3)); cb.writeByte(scrambleBufferSize.byteValue()); cb.writeZero(10); // write 10 unused bytes cb.writeBytes(scrambleBuffer2nd.getBytes()); // Salt cb.writeBytes(getPlugInProvidedData().getBytes()); // payload cb.writeZero(1); }
From source file:com.tesora.dve.db.mysql.libmy.MyLoginRequest.java
License:Open Source License
@Override public void marshallMessage(ByteBuf cb) { boolean hasConnectDatabase = false; if (database != null) { clientCapabilities = clientCapabilities + ClientCapabilities.CLIENT_CONNECT_WITH_DB; hasConnectDatabase = true;//from w w w .j a va 2 s. com } cb.writeInt((int) clientCapabilities); cb.writeInt(maxPacketSize); cb.writeByte(clientCharset); cb.writeZero(23); // filler cb.writeBytes(username.getBytes(CharsetUtil.UTF_8)); cb.writeZero(1); // null terminator for username byte[] passwordBytes = password.getBytes(CharsetUtil.ISO_8859_1); MysqlAPIUtils.putLengthCodedString(cb, passwordBytes, false); if (hasConnectDatabase) { cb.writeBytes(database.getBytes(CharsetUtil.UTF_8)); cb.writeZero(1); // null terminator for database } if (plugInData != null) { cb.writeBytes(plugInData.getBytes(CharsetUtil.UTF_8)); cb.writeZero(1); // null terminator for plugInData } }
From source file:com.tesora.dve.db.mysql.libmy.MyPrepareOKResponse.java
License:Open Source License
@Override public void marshallMessage(ByteBuf cb) { cb.writeZero(1); // status cb.writeInt((int) stmtId); cb.writeShort(numColumns);/*from w w w. j a v a 2 s . c o m*/ cb.writeShort(numParams); cb.writeZero(1); // filler cb.writeShort(warningCount); }
From source file:com.tesora.dve.db.mysql.portal.protocol.MSPAuthenticateV10MessageMessage.java
License:Open Source License
public static void write(ByteBuf out, String userName, String userPassword, String salt, Charset charset, int mysqlCharsetID, int capabilitiesFlag) { ByteBuf leBuf = out.order(ByteOrder.LITTLE_ENDIAN); int payloadSizeIndex = leBuf.writerIndex(); leBuf.writeMedium(0);/*from w ww . j a va2s .c o m*/ leBuf.writeByte(1); int payloadStartIndex = leBuf.writerIndex(); leBuf.writeInt(capabilitiesFlag); leBuf.writeInt(MAX_PACKET_SIZE); // leBuf.writeByte(serverGreeting.getServerCharsetId()); leBuf.writeByte(mysqlCharsetID); leBuf.writeZero(23); leBuf.writeBytes(userName.getBytes(charset)); leBuf.writeZero(1); if ((capabilitiesFlag & ClientCapabilities.CLIENT_SECURE_CONNECTION) > 0) { byte[] securePassword = computeSecurePassword(userPassword, salt); leBuf.writeByte(securePassword.length); leBuf.writeBytes(securePassword); } else { leBuf.writeBytes(userPassword.getBytes(charset)); leBuf.writeZero(1); } leBuf.setMedium(payloadSizeIndex, leBuf.writerIndex() - payloadStartIndex); }
From source file:com.tesora.dve.db.mysql.portal.protocol.MSPComStmtCloseRequestMessage.java
License:Open Source License
@Override protected void marshall(Long statementID, ByteBuf destination) { destination.writeByte(TYPE_IDENTIFIER); destination.writeInt(statementID.intValue()); }
From source file:com.tesora.dve.db.mysql.portal.protocol.MSPComStmtExecuteRequestMessage.java
License:Open Source License
@Override protected void marshall(ParsedData state, ByteBuf destination) { ByteBuf leBuf = destination.order(ByteOrder.LITTLE_ENDIAN); leBuf.writeByte(TYPE_IDENTIFIER);/*from w ww.j a va 2 s . c o m*/ leBuf.writeInt((int) state.statementID); leBuf.writeByte(state.flags); leBuf.writeInt((int) state.iterationCount); if (state.metadata == null) throw new IllegalStateException("Cannot build execute request, no prepare metadata provided."); int numParams = state.metadata.getNumParams(); if (numParams > 0) { MyNullBitmap nullBitmap = new MyNullBitmap(numParams, MyNullBitmap.BitmapType.EXECUTE_REQUEST); int bitmapIndex = leBuf.writerIndex(); leBuf.writeZero(nullBitmap.length()); if (state.metadata.isNewParameterList()) { leBuf.writeByte(1); for (MyParameter param : state.metadata.getParameters()) { leBuf.writeByte(param.getType().getByteValue()); leBuf.writeZero(1); } } else { leBuf.writeZero(1); } List<Object> params = state.values; for (int i = 0; i < params.size(); ++i) { if (params.get(i) != null) DBTypeBasedUtils.getJavaTypeFunc(params.get(i).getClass()).writeObject(leBuf, params.get(i)); else nullBitmap.setBit(i + 1); } leBuf.setBytes(bitmapIndex, nullBitmap.getBitmapArray()); } }
From source file:com.tesora.dve.db.mysql.portal.protocol.MSPServerGreetingRequestMessage.java
License:Open Source License
public static void write(ChannelHandlerContext ctx, int connectionId, String salt, int serverCapabilities, String serverVersion, byte serverCharSet, String pluginData) { ByteBuf out = ctx.channel().alloc().heapBuffer(50).order(ByteOrder.LITTLE_ENDIAN); String scrambleBuffer1st = salt.substring(0, 8); String scrambleBuffer2nd = salt.substring(8) + '\0'; Integer scrambleBufferSize = scrambleBuffer1st.length() + scrambleBuffer2nd.length(); ByteBuf serverCapabilitiesBuf = ctx.channel().alloc().heapBuffer(4).order(ByteOrder.LITTLE_ENDIAN); try {/*from w w w .j a v a 2 s . c om*/ serverCapabilitiesBuf.writeInt(serverCapabilities); out.writeMedium(0); out.writeByte(0); out.writeByte(MYSQL_PROTOCOL_VERSION); out.writeBytes(serverVersion.getBytes()); out.writeZero(1); out.writeInt(connectionId); out.writeBytes(scrambleBuffer1st.getBytes()); // Salt out.writeZero(1); out.writeByte(serverCapabilitiesBuf.getByte(0)); out.writeByte(serverCapabilitiesBuf.getByte(1)); out.writeByte(serverCharSet); out.writeShort(MyProtocolDefs.SERVER_STATUS_AUTOCOMMIT); out.writeByte(serverCapabilitiesBuf.getByte(2)); out.writeByte(serverCapabilitiesBuf.getByte(3)); out.writeByte(scrambleBufferSize.byteValue()); out.writeZero(10); // write 10 unused bytes out.writeBytes(scrambleBuffer2nd.getBytes()); // Salt out.writeBytes(pluginData.getBytes()); // payload out.writeZero(1); out.setMedium(0, out.writerIndex() - 4); ctx.channel().writeAndFlush(out); } finally { serverCapabilitiesBuf.release(); } }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyAppendBlockLogEvent.java
License:Open Source License
@Override public void marshallMessage(ByteBuf cb) { cb.writeInt(fileId); cb.writeBytes(dataBlock); }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyComBinLogDumpRequest.java
License:Open Source License
@Override public void marshallMessage(ByteBuf cb) { cb.writeInt((int) binlogPosition); cb.writeZero(2); // binlog_flags cb.writeInt(slaveServerID);/*ww w.java2 s .c o m*/ if (binlogFileName != null) { cb.writeBytes(binlogFileName.getBytes(CharsetUtil.UTF_8)); } }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyComRegisterSlaveRequest.java
License:Open Source License
@Override public void marshallMessage(ByteBuf cb) { cb.writeInt(slaveServerId); MysqlAPIUtils.putLengthCodedString(cb, reportHost, true /* codeNullasZero */); MysqlAPIUtils.putLengthCodedString(cb, reportUser, true /* codeNullasZero */); MysqlAPIUtils.putLengthCodedString(cb, reportPassword, true /* codeNullasZero */); cb.writeShort(reportPort);/*w w w . j av a 2 s . co m*/ cb.writeZero(8); }