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.portal.protocol.Packet.java

License:Open Source License

public static int encodeFullPayload(int sequenceStart, ByteBuf payloadHolder, ByteBuf destination) {
    ByteBuf leBuf = destination.order(ByteOrder.LITTLE_ENDIAN);

    //TODO: this loop is identical to the one below, except it doesn't consume the source or update the destination.  Consolidate?
    //calculate the size of the final encoding, so we resize the destination at most once.
    int payloadRemaining = payloadHolder.readableBytes();
    int outputSize = 0;
    do {//w ww. j  a  v  a 2  s .co m
        outputSize += 4; //header
        int chunkLength = Math.min(payloadRemaining, MAX_PAYLOAD);
        outputSize += chunkLength;
        payloadRemaining -= chunkLength;
        if (chunkLength == MAX_PAYLOAD)
            outputSize += 4; //need one more packet if last fragment is exactly 0xFFFF long.
    } while (payloadRemaining > 0);

    leBuf.ensureWritable(outputSize);

    int sequenceIter = sequenceStart;
    boolean lastChunkWasMaximumLength;
    do {
        int initialSize = payloadHolder.readableBytes();
        int maxSlice = MAX_PAYLOAD;
        int sendingPayloadSize = Math.min(maxSlice, initialSize);
        lastChunkWasMaximumLength = (sendingPayloadSize == maxSlice); //need to send a zero length payload if last fragment was exactly 0xFFFF long.

        ByteBuf nextChunk = payloadHolder.readSlice(sendingPayloadSize);
        leBuf.writeMedium(sendingPayloadSize);
        leBuf.writeByte(sequenceIter);
        leBuf.writeBytes(nextChunk);

        sequenceIter++;
    } while (payloadHolder.readableBytes() > 0 || lastChunkWasMaximumLength);
    return sequenceIter; //returns the next usable/expected sequence number.
}

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  w  ww. jav 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);//  ww  w  .  ja v  a2  s  . c o m
    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)));
        }
        cb.writeZero(1);
        break;

    default:
        break;
    }
}

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

License:Open Source License

@Override
public void marshallMessage(ByteBuf cb) {
    cb.writeByte(variableType);
    cb.writeLong(variableValue.longValue());
}

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

License:Open Source License

@Override
public void marshallMessage(ByteBuf cb) {
    cb.writeInt(threadId);/*from w  ww  .  j a v a  2 s  . c  o  m*/
    cb.writeInt(time);
    cb.writeInt(ignoreLines);
    cb.writeByte(tableLen);
    cb.writeByte(dbLen);
    cb.writeInt(columns);
    cb.writeBytes(variableData);
}

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());
    cb.writeShort(getErrorCode());//  w  w w  .  j a  va 2  s  .c om
    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());
    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  ww  w . j av a  2 s .  com
    }
}

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
                }/*from w  w w .j  a v a  2 s  . com*/
            }
            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;
        }
    }
}

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

License:Open Source License

@Override
public void marshallMessage(ByteBuf cb) {
    cb.writeInt(variableNameLen);//from w ww  .  j  av a  2  s . c o m
    cb.writeBytes(variableName.getBytes(CharsetUtil.UTF_8));
    cb.writeByte(nullByte);
    if (nullByte != 1) {
        cb.writeByte(valueType.getByteValue());
        cb.writeInt(valueCharSet);
        cb.writeInt(valueLen);
        cb.writeBytes(valueBytes);
    }
}

From source file:com.turn.ttorrent.client.io.PeerHandshakeMessage.java

License:Apache License

public void toWire(@Nonnull ByteBuf out) {
    out.writeByte(protocolName.length);
    out.writeBytes(protocolName);/*  www  .  j  a  v  a 2s .  c om*/
    out.writeBytes(reserved);
    out.writeBytes(infoHash);
    out.writeBytes(peerId);
}