Example usage for io.netty.buffer ByteBuf writeInt

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

Introduction

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

Prototype

public abstract ByteBuf writeInt(int value);

Source Link

Document

Sets the specified 32-bit integer at the current writerIndex and increases the writerIndex by 4 in this buffer.

Usage

From source file:com.streamsets.pipeline.lib.parser.net.netflow.NetflowTestUtil.java

License:Apache License

public static void writeV5NetflowFlowRecord(EmbeddedChannel channel, long srcAddr, long destAddr, long nextHop,
        int snmpInput, int snmpOutput, long packets, long octets, long first, long last, int srcPort,
        int destPort, int tcpFlags, int proto, int tos, int srcAs, int destAs, int srcMask, int destMask

) {//from ww  w. j  av a  2 s  .c  o m

    final ByteBuf buf = Unpooled.buffer();
    buf.writeInt((int) srcAddr);
    buf.writeInt((int) destAddr);
    buf.writeInt((int) nextHop);
    buf.writeShort(snmpInput);
    buf.writeShort(snmpOutput);
    buf.writeInt((int) packets);
    buf.writeInt((int) octets);
    buf.writeInt((int) first);
    buf.writeInt((int) last);
    buf.writeShort(srcPort);
    buf.writeShort(destPort);
    // one empty pad byte
    buf.writeByte(0);
    buf.writeByte(tcpFlags);
    buf.writeByte(proto);
    buf.writeByte(tos);
    buf.writeShort(srcAs);
    buf.writeShort(destAs);
    buf.writeByte(srcMask);
    buf.writeByte(destMask);
    // two empty pad bytes
    buf.writeByte(0);
    buf.writeByte(0);
    channel.writeInbound(buf);
}

From source file:com.teambr.bookshelf.network.SyncableFieldPacket.java

License:Creative Commons License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeBoolean(returnValue);//ww  w. j a  va  2  s. co m
    buf.writeInt(id);
    buf.writeDouble(value);
    buf.writeLong(blockPosition.toLong());
}

From source file:com.teambr.modularsystems.core.network.DeleteValuesPacket.java

License:Creative Commons License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(this.blockID);
    buf.writeInt(this.meta);
}

From source file:com.teambr.modularsystems.core.network.SyncBlockValues.java

License:Creative Commons License

@Override
public void toBytes(ByteBuf buf) {
    byte[] compressedBytes = null;

    if (jsonBlockValues != null)
        compressedBytes = CompressionFunctions.compressStringToByteArray(jsonBlockValues);

    if (compressedBytes != null) {
        buf.writeInt(compressedBytes.length);
        buf.writeBytes(compressedBytes);
    } else//from   www  .ja  va 2  s  . c  o m
        buf.writeInt(0);
}

From source file:com.teambr.modularsystems.storage.network.StorageMessage.java

License:Creative Commons License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(message.ordinal());
}

From source file:com.teambrmodding.neotech.network.OpenContainerGuiPacket.java

License:Creative Commons License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeLong(blockPos.toLong());
    buf.writeInt(id);
}

From source file:com.tesora.dve.db.mysql.common.MysqlAPIUtils.java

License:Open Source License

public static void putLengthCodedDate(ByteBuf cb, Date inDate) {
    byte length = 0;
    Calendar cal = null;/*w  w  w  .j  a v  a2  s .c  om*/
    if (inDate != null) {
        cal = DateUtils.toCalendar(inDate);
        if (cal.get(Calendar.MILLISECOND) > 0) { // indicates we need full 11 byte date
            length = 11;
        } else if (cal.get(Calendar.HOUR_OF_DAY) > 0 || cal.get(Calendar.MINUTE) > 0
                || cal.get(Calendar.SECOND) > 0) { // this is the 7 byte format
            length = 7;
        } else if (cal.get(Calendar.YEAR) > 0 || cal.get(Calendar.MONTH) > 0
                || cal.get(Calendar.DAY_OF_MONTH) > 0) {
            length = 4;
        }
    }
    cb.writeByte(length);
    if (length >= 4) {
        cb.writeShort(cal.get(Calendar.YEAR));
        cb.writeByte(cal.get(Calendar.MONTH) + 1); // MONTH is zero based
        cb.writeByte(cal.get(Calendar.DAY_OF_MONTH));
    }
    if (length >= 7) {
        cb.writeByte(cal.get(Calendar.HOUR_OF_DAY));
        cb.writeByte(cal.get(Calendar.MINUTE));
        cb.writeByte(cal.get(Calendar.SECOND));
    }
    if (length == 11) {
        // 1 millisecond = 1000 microseconds, right?
        int microSeconds = cal.get(Calendar.MILLISECOND) * 1000;
        cb.writeInt(microSeconds);
    }
}

From source file:com.tesora.dve.db.mysql.common.MysqlAPIUtils.java

License:Open Source License

public static void putLengthCodedTime(ByteBuf cb, Time inTime) {
    byte length = 0;
    Calendar cal = null;/*from  www  . j  a v a 2s.c o m*/
    if (inTime != null) {
        cal = DateUtils.toCalendar(inTime);
        if (cal.get(Calendar.MILLISECOND) > 0) { // indicates we need full 12 byte date
            length = 12;
        } else if (cal.get(Calendar.HOUR_OF_DAY) > 0 || cal.get(Calendar.MINUTE) > 0
                || cal.get(Calendar.SECOND) > 0) { // this is the 8 byte format
            length = 8;
        }
    }
    cb.writeByte(length);
    if (length >= 8) {
        cb.writeZero(5); // this is the sign and days - we are not supporting this
        cb.writeByte(cal.get(Calendar.HOUR_OF_DAY));
        cb.writeByte(cal.get(Calendar.MINUTE));
        cb.writeByte(cal.get(Calendar.SECOND));
    }
    if (length == 12) {
        // 1 millisecond = 1000 microseconds, right?
        int microSeconds = cal.get(Calendar.MILLISECOND) * 1000;
        cb.writeInt(microSeconds);
    }
}

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

License:Open Source License

public void marshallMessage(ByteBuf stmtExecuteBuf) {
    //header and type are marshalled by parent class.

    int rowsToFlush = this.size();

    MyNullBitmap nullBitmap = new MyNullBitmap(rowsToFlush * columnsPerTuple,
            MyNullBitmap.BitmapType.EXECUTE_REQUEST);

    //            stmtExecuteBuf.writeByte(MSPComStmtExecuteRequestMessage.TYPE_IDENTIFIER);
    stmtExecuteBuf.writeInt(this.stmtID);
    stmtExecuteBuf.writeZero(1); // flags
    stmtExecuteBuf.writeInt(1); // iteration count
    int nullBitmapIndex = stmtExecuteBuf.writerIndex();
    stmtExecuteBuf.writeZero(nullBitmap.length());

    // write the parameter types, as appropriate
    if (this.needsNewParams) {
        stmtExecuteBuf.writeByte(1);//from  w  w  w.  j  a  va2s. co m

        for (int i = 0; i < rowsToFlush; ++i) {
            stmtExecuteBuf.writeBytes(metadataFragment.slice());
        }

    } else
        stmtExecuteBuf.writeZero(1);

    // Copy the parameter values, updating the null bitmap
    // null bitmap is 1-based
    int rowsWritten = 0;
    int execStmtColIndex = 1;
    for (Iterator<MyBinaryResultRow> i = this.queuedPackets.iterator(); i.hasNext();) {
        MyBinaryResultRow rowPacketData = i.next();

        //                ByteBuf rowSet = Unpooled.buffer(rowPacketData.binRow.sizeInBytes()).order(ByteOrder.LITTLE_ENDIAN);
        //                rowPacketData.binRow.marshallFullMessage(rowSet);

        //                while (rowSet.isReadable() && rowsToWrite-- > 0) {
        //            System.out.println(siteCtx + "/" + myi + ": adding row");
        //                    int payloadLen = rowSet.readMedium();
        //                    rowSet.skipBytes(1);
        //                    byte packetHeader = rowSet.readByte();
        //                    if (packetHeader != 0)
        //                        throw new PEException("Out-of-sync reading redist rowSet");
        int bitmapSize = MyNullBitmap.computeSize(columnsPerTuple, MyNullBitmap.BitmapType.RESULT_ROW);
        int rowFields = rowPacketData.size();
        for (int colIndex = 1; colIndex <= columnsPerTuple; colIndex++, execStmtColIndex++) {
            //we are looping through target columns, which may exceed the source column count.
            if ((colIndex <= rowFields) && rowPacketData.isNull(colIndex - 1 /* zero based indexing */))
                nullBitmap.setBit(execStmtColIndex);
        }
        //                    rowSet.skipBytes(bitmapSize);

        //                    stmtExecuteBuf.writeBytes(rowSet, payloadLen-bitmapSize-1);
        rowPacketData.marshallRawValues(stmtExecuteBuf);
        ++rowsWritten;

    }

    if (rowsWritten != rowsToFlush) {
        //         System.out.println("At failure " + stmtExecuteBuf + "/" + siteCtx);
        throw new PECodingException("Asked to write " + rowsToFlush + " rows, but only " + rowsWritten
                + " were (" + rowsToFlush + " were made available to flushBuffers)");
    }

    // Go back and set the null bitmap and the payload size
    stmtExecuteBuf.setBytes(nullBitmapIndex, nullBitmap.getBitmapArray());
}

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

License:Open Source License

public void fullPack(ByteBuf cb) {
    MysqlAPIUtils.putLengthCodedString(cb, catalog, true);
    MysqlAPIUtils.putLengthCodedString(cb, database, true);
    MysqlAPIUtils.putLengthCodedString(cb, table, true);
    MysqlAPIUtils.putLengthCodedString(cb, orig_table, true);
    MysqlAPIUtils.putLengthCodedString(cb, column, true);
    MysqlAPIUtils.putLengthCodedString(cb, orig_column, true);
    // The "spec" I used said this next byte was "filler", thru investigation
    // we determined that it is the number of bytes to the end of
    // the packet (not including the default). It seems to be always 12
    cb.writeByte((byte) 12);
    cb.writeByte(charset);//w ww . ja  va2s .co m
    cb.writeZero(1);
    cb.writeInt(column_length);
    cb.writeByte(column_type.getByteValue());
    cb.writeShort(flags);
    cb.writeByte(scale);
    cb.writeZero(2);
}