Example usage for io.netty.buffer ByteBuf writeByte

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

Introduction

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

Prototype

public abstract ByteBuf writeByte(int value);

Source Link

Document

Sets the specified byte at the current writerIndex and increases the writerIndex by 1 in this buffer.

Usage

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 ww .  j  a  va 2  s  .c o m*/
    }
    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.MyMessage.java

License:Open Source License

public void marshallPayload(ByteBuf destination) {
    destination = destination.order(ByteOrder.LITTLE_ENDIAN);

    if (this.isMessageTypeEncoded())
        destination.writeByte(this.getMessageType().getByteValue());

    this.marshallMessage(destination);
}

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

License:Open Source License

@Override
public void marshallMessage(ByteBuf in) {
    ByteBuf cb = in.order(ByteOrder.LITTLE_ENDIAN);
    cb.writeByte(0); // field_count - spec says this is always 0
    MysqlAPIUtils.putLengthCodedLong(cb, affectedRows);
    MysqlAPIUtils.putLengthCodedLong(cb, insertId);
    cb.writeShort(serverStatus);//from  w ww . java  2 s.c  o m
    cb.writeShort(warningCount);
    if (message != null && message.length() > 0) {
        cb.writeBytes(message.getBytes());
    }
}

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

License:Open Source License

@Override
public void marshallMessage(ByteBuf cb) {
    cb.writeByte(ERRORPKT_FIELD_COUNT);
    cb.writeShort((short) getErrorNumber());
    cb.writeBytes(getErrorMsg().getBytes());
}

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);// w w  w.j  a  v a2s  .co  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.MSPComPrepareStmtRequestMessage.java

License:Open Source License

@Override
protected void marshall(String state, ByteBuf destination) {
    destination.writeByte(getMysqlMessageType());
    destination.writeBytes(decodingCharset.encode(state));
}

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

License:Open Source License

public static MSPComQueryRequestMessage newMessage(byte[] rawQuery) {
    ByteBuf buf = Unpooled.buffer().order(ByteOrder.LITTLE_ENDIAN).ensureWritable(rawQuery.length + 1);
    buf.writeByte(TYPE_IDENTIFIER);
    buf.writeBytes(rawQuery);/*from   w w  w  .  jav  a 2 s  .  com*/
    return new MSPComQueryRequestMessage(buf);
}

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);
    leBuf.writeInt((int) state.statementID);
    leBuf.writeByte(state.flags);/* www.ja va  2 s  .c o  m*/
    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 {//w  w w. j av a 2s.  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();
    }
}