Example usage for io.netty.buffer ByteBuf writeBytes

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

Introduction

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

Prototype

public abstract ByteBuf writeBytes(ByteBuffer src);

Source Link

Document

Transfers the specified source buffer's data to this buffer starting at the current writerIndex until the source buffer's position reaches its limit, and increases the writerIndex by the number of the transferred bytes.

Usage

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

License:Open Source License

@Override
public void unmarshallMessage(ByteBuf cb) {
    ByteBuf newCache = Unpooled.buffer(cb.readableBytes()).order(ByteOrder.LITTLE_ENDIAN);
    newCache.writeBytes(cb);

    updateCache(newCache);//from  ww w. j  a v a 2s.  c  o  m

    //parsing variable length name info is expensive, only unpack fixed length type info by default.
    unpackTypeInfo(cachedBuffer.slice());

    state = CacheState.PACKED;
}

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

License:Open Source License

@Override
public void marshallMessage(ByteBuf cb) {
    cb.writeByte(ERRORPKT_FIELD_COUNT);//  w  w  w .  ja v a 2  s .co  m
    cb.writeShort((short) getErrorNumber());
    cb.writeBytes(getErrorMsg().getBytes(charset));
}

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

License:Open Source License

@Override
public void marshallMessage(ByteBuf cb) {
    cb.writeByte(protocolVersion);//from  w  ww.  j  av a2s .  c o m
    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.MyLoadDataResponse.java

License:Open Source License

@Override
public void marshallMessage(ByteBuf cb) {
    cb.writeByte(0xFB);
    cb.writeBytes(fileName.getBytes(CharsetUtil.UTF_8));
}

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;/* w w w  .j  a v  a 2  s  .  co  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.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);//w  ww . j av a  2s. c  om
    cb.writeShort(warningCount);
    if (message != null && message.length() > 0) {
        cb.writeBytes(message.getBytes());
    }
}

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

License:Open Source License

@Override
public void marshallMessage(ByteBuf cb) {
    cb.writeBytes(heapBuffer.slice());
}

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);/*from  ww w.ja  v a2  s  .  c o  m*/
    cb.writeShort((short) getErrorNumber());
    cb.writeBytes(getErrorMsg().getBytes());
}

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

License:Open Source License

@Override
public void marshallMessage(ByteBuf cb) {

    StringBuffer message = new StringBuffer(110);
    message.append("Uptime: ").append(uptime);
    message.append(" Threads: ").append(threads);
    message.append(" Questions: ").append(questions);
    message.append(" Slow queries: ").append(slowQueries);
    message.append(" Opens: ").append(opens);
    message.append(" Flush tables: ").append(flushTables);
    message.append(" Open tables: ").append(openTables);
    message.append(" Queries per second avg: ").append(new DecimalFormat("#0.000").format(queriesPerSecAvg));
    cb.writeBytes(message.toString().getBytes());
}

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

License:Open Source License

@Override
public void marshallMessage(ByteBuf cb) {
    cb.writeBytes(backingBuffer.slice());
}