Example usage for io.netty.buffer ByteBuf writeShort

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

Introduction

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

Prototype

public abstract ByteBuf writeShort(int value);

Source Link

Document

Sets the specified 16-bit short integer at the current writerIndex and increases the writerIndex by 2 in this buffer.

Usage

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

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);
    cb.writeShort(numParams);//ww  w .java  2s .c  o  m
    cb.writeZero(1); // filler
    cb.writeShort(warningCount);
}

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.  j  av a2s  . com
    cb.writeShort((short) getErrorNumber());
    cb.writeBytes(getErrorMsg().getBytes());
}

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 ww . j a  va 2 s .  c  o  m
        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.MyComRegisterSlaveRequest.java

License:Open Source License

@Override
public void marshallMessage(ByteBuf cb) {
    cb.writeInt(slaveServerId);/*from  w w w.  j a v a 2 s .  c  o  m*/
    MysqlAPIUtils.putLengthCodedString(cb, reportHost, true /* codeNullasZero */);
    MysqlAPIUtils.putLengthCodedString(cb, reportUser, true /* codeNullasZero */);
    MysqlAPIUtils.putLengthCodedString(cb, reportPassword, true /* codeNullasZero */);
    cb.writeShort(reportPort);
    cb.writeZero(8);
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyExecuteLoadLogEvent.java

License:Open Source License

@Override
public void marshallMessage(ByteBuf cb) {
    cb.writeInt(threadId);//from  ww  w  . j a  v a  2 s  . co m
    cb.writeInt(time);
    cb.writeByte(dbLen);
    cb.writeShort(errorCode);
    cb.writeShort(statusBlockLen);
    cb.writeInt(fileId);
    cb.writeInt(startPos);
    cb.writeInt(endPos);
    cb.writeByte(duplicateFlag);

    statusVars.writeStatusVariables(cb);

    cb.writeBytes(dbName.getBytes(CharsetUtil.UTF_8));
    cb.writeByte(0); //for trailing 0
    cb.writeBytes(query);
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyFormatDescriptionLogEvent.java

License:Open Source License

@Override
public void marshallMessage(ByteBuf cb) {
    cb.writeShort(binaryLogVersion);
    cb.writeBytes(serverVersion.getBytes(CharsetUtil.UTF_8));
    cb.writeInt((int) createTime);
    cb.writeByte(0xFF & eventTypeLength);
    switch (MyBinLogVerType.fromByte((byte) binaryLogVersion)) {

    case MySQL_5_0:
        for (int i = 1; i <= eventTypeValues.size(); i++) {
            cb.writeByte(eventTypeValues.get(MyLogEventType.fromByte((byte) i)));
        }//from  www.  jav  a 2 s. c  om
        cb.writeZero(1);
        break;

    default:
        break;
    }
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyQueryLogEvent.java

License:Open Source License

@Override
public void marshallMessage(ByteBuf cb) {
    cb.writeInt((int) getSlaveProxyId());
    cb.writeInt((int) getExecTime());
    cb.writeByte(getDbNameLen());/*  w  ww.  j  ava2  s.  co  m*/
    cb.writeShort(getErrorCode());
    cb.writeShort(getStatusVarsLen());

    statusVars.writeStatusVariables(cb);

    cb.writeBytes(getDbName().getBytes(CharsetUtil.UTF_8));
    cb.writeByte(0); //for trailing 0
    cb.writeBytes(getQuery());
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyReplEvent.java

License:Open Source License

@Override
public void marshallMessage(ByteBuf cb) {
    cb.writeInt((int) commonHdr.getTimestamp());
    cb.writeByte(commonHdr.getType());//from  w ww.  j  av a2  s .  c  om
    cb.writeInt((int) commonHdr.getServerId());
    cb.writeInt((int) commonHdr.getTotalSize());
    cb.writeInt((int) commonHdr.getMasterLogPosition());
    cb.writeShort(commonHdr.getFlags());

    if (levp != null) {
        levp.marshallMessage(cb);
    }
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyStatusVariables.java

License:Open Source License

public void writeStatusVariables(ByteBuf cb) {
    for (BaseQueryEvent qe : getSuppliedEventCodes()) {
        MyQueryEventCode code = qe.getCode();
        switch (code) {
        case Q_FLAGS2_CODE:
            cb.writeByte(code.getByteValue());
            cb.writeInt(((QueryFlags2Event) qe).getFlags());
            break;

        case Q_SQL_MODE_CODE:
            cb.writeByte(code.getByteValue());
            cb.writeLong(((QuerySQLModeEvent) qe).getSqlMode());
            break;

        case Q_CATALOG_CODE:
            cb.writeByte(code.getByteValue());
            cb.writeByte(((QueryCatalogEvent) qe).getCatalog().length());
            cb.writeBytes(((QueryCatalogEvent) qe).getCatalog().getBytes());
            cb.writeByte(0); //for trailing 0
            break;

        case Q_AUTO_INCREMENT:
            cb.writeByte(code.getByteValue());
            cb.writeShort(((QueryAutoIncrementEvent) qe).getAutoIncrementIncrement());
            cb.writeShort(((QueryAutoIncrementEvent) qe).getAutoIncrementOffset());
            break;

        case Q_CHARSET_CODE:
            cb.writeByte(code.getByteValue());
            cb.writeShort(((QueryCharSetCodeEvent) qe).getCharSetClient());
            cb.writeShort(((QueryCharSetCodeEvent) qe).getCollationConnection());
            cb.writeShort(((QueryCharSetCodeEvent) qe).getCollationServer());
            break;

        case Q_TIME_ZONE_CODE:
            cb.writeByte(code.getByteValue());
            cb.writeByte(((QueryTimeZoneCodeEvent) qe).getTimeZone().length());
            cb.writeBytes(((QueryTimeZoneCodeEvent) qe).getTimeZone().getBytes());
            break;

        case Q_CATALOG_NZ_CODE:
            cb.writeByte(code.getByteValue());
            cb.writeByte(((QueryCatalogNZEvent) qe).getCatalog().length());
            cb.writeBytes(((QueryCatalogNZEvent) qe).getCatalog().getBytes());
            break;

        case Q_LC_TIME_NAMES_CODE:
            cb.writeByte(code.getByteValue());
            cb.writeShort(((QueryTimeNamesEvent) qe).getMonthDayNames());
            break;

        case Q_CHARSET_DATABASE_CODE:
            cb.writeByte(code.getByteValue());
            cb.writeShort(((QueryCollationDatabaseEvent) qe).getCollationDatabase());
            break;

        case Q_TABLE_MAP_FOR_UPDATE_CODE:
            cb.writeByte(code.getByteValue());
            cb.writeLong(((QueryTableMapEvent) qe).getTableMapForUpdate());
            break;

        case Q_MASTER_DATA_WRITTEN_CODE:
            cb.writeByte(code.getByteValue());
            cb.writeInt(((QueryMasterDataWrittenEvent) qe).getOriginalLength());
            break;

        case Q_INVOKER:
            cb.writeByte(code.getByteValue());
            cb.writeByte(((QueryInvokerEvent) qe).getUser().length());
            cb.writeBytes(((QueryInvokerEvent) qe).getUser().getBytes());
            cb.writeByte(((QueryInvokerEvent) qe).getHost().length());
            cb.writeBytes(((QueryInvokerEvent) qe).getHost().getBytes());
            break;

        case Q_UPDATED_DB_NAMES:
            cb.writeByte(code.getByteValue());
            List<String> dbs = ((QueryUpdatedDBNamesEvent) qe).getDbNames();
            cb.writeByte(dbs == null ? 0 : dbs.size());
            if (dbs.size() > 0) {
                for (String db : dbs) {
                    cb.writeByte(db.length());
                    cb.writeBytes(db.getBytes(CharsetUtil.UTF_8));
                    cb.writeByte(0); //for trailing 0
                }//ww  w. j  ava2  s. co  m
            }
            break;

        case Q_MICROSECONDS:
            cb.writeByte(code.getByteValue());
            cb.writeMedium(((QueryMicrosecondsEvent) qe).getMicroseconds());
            break;

        case Q_HRNOW:
            cb.writeMedium(((QueryHRNowEvent) qe).threeBytes);
            break;

        default:
            break;
        }
    }
}