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.heliosapm.ohcrs.core.AbstractDriverCodec.java

License:Apache License

/**
 * {@inheritDoc}//from w  w  w .  j  a  v a  2 s.  com
 * @see com.heliosapm.ohcrs.core.DriverCodec#write(int, io.netty.buffer.ByteBuf)
 */
@Override
public int write(final int p, final ByteBuf b) throws SQLException {
    prefix(P, DBType.INTEGER, b);
    b.writeInt(p);
    return b.writerIndex();
}

From source file:com.heliosapm.ohcrs.impls.oracle.OracleDriverCodec.java

License:Apache License

/**
 * {@inheritDoc}//  www .j  a v a  2 s  .co m
 * @see com.heliosapm.ohcrs.core.DriverCodec#write(java.lang.Object, com.heliosapm.ohcrs.core.DBType, io.netty.buffer.ByteBuf)
 */
@Override
public int write(final Datum t, final DBType d, final ByteBuf b) throws SQLException {
    if (prefix(t, d, b)) {
        final byte[] bytes = t.getBytes();
        b.writeInt(bytes.length);
        if (t instanceof oracle.sql.CHAR) {
            b.writeInt(((oracle.sql.CHAR) t).oracleId());
        }
        b.writeBytes(bytes);
    }
    return b.readerIndex();
}

From source file:com.hxr.javatone.concurrency.netty.official.factorial.NumberEncoder.java

License:Apache License

@Override
protected void encode(ChannelHandlerContext ctx, Number msg, ByteBuf out) throws Exception {
    // Convert to a BigInteger first for easier implementation.
    BigInteger v;//from   ww w.  ja va2 s. c  om
    if (msg instanceof BigInteger) {
        v = (BigInteger) msg;
    } else {
        v = new BigInteger(String.valueOf(msg));
    }

    // Convert the number into a byte array.
    byte[] data = v.toByteArray();
    int dataLength = data.length;

    // Write a message.
    out.writeByte((byte) 'F'); // magic number
    out.writeInt(dataLength); // data length
    out.writeBytes(data); // data
}

From source file:com.ibm.crail.datanode.netty.rpc.RdmaMsgHeader.java

License:Apache License

public void encode(ByteBuf target) {
    target.writeLong(address);//from  www.  j a va 2 s.  c o  m
    target.writeInt(opLength);
    target.writeInt(stag);
    target.writeInt(type);
    target.writeInt(status);
    target.writeLong(cookie);
}

From source file:com.irh.material.basics.netty.chapter14_1.codec.NettyMessageEncoder.java

License:Apache License

@Override
protected void encode(ChannelHandlerContext ctx, NettyMessage msg, ByteBuf sendBuf) throws Exception {
    if (msg == null || msg.getHeader() == null) {
        throw new Exception("The encode message is null");
    }/*from ww  w  . j  a v a2  s .c om*/
    sendBuf.writeInt((msg.getHeader().getCrcCode()));
    sendBuf.writeInt((msg.getHeader().getLength()));
    sendBuf.writeLong((msg.getHeader().getSessionID()));
    sendBuf.writeByte((msg.getHeader().getType()));
    sendBuf.writeByte((msg.getHeader().getPriority()));
    sendBuf.writeInt((msg.getHeader().getAttachment().size()));
    String key = null;
    byte[] keyArray = null;
    Object value = null;
    for (Map.Entry<String, Object> param : msg.getHeader().getAttachment().entrySet()) {
        key = param.getKey();
        keyArray = key.getBytes("UTF-8");
        sendBuf.writeInt(keyArray.length);
        sendBuf.writeBytes(keyArray);
        value = param.getValue();
        marshallingEncoder.encode(value, sendBuf);
    }
    key = null;
    keyArray = null;
    value = null;
    if (msg.getBody() != null) {
        marshallingEncoder.encode(msg.getBody(), sendBuf);
    } else
        sendBuf.writeInt(0);
    sendBuf.setInt(4, sendBuf.readableBytes() - 8);
}

From source file:com.jadarstudios.rankcapes.forge.network.packet.PacketBase.java

License:MIT License

/**
 * Write a string to a {@link ByteBuf}/*from  w w  w  . ja v a  2s .  c  om*/
 *
 * @param string the string to write
 * @param data   the buffer to write to
 *
 * @throws IndexOutOfBoundsException thrown if the buffer is too small for the data
 */
public void writeString(String string, ByteBuf data) throws IndexOutOfBoundsException {
    byte[] stringBytes = string.getBytes();
    data.writeInt(stringBytes.length);
    data.writeBytes(stringBytes);
}

From source file:com.jayqqaa12.jbase.tcp.netty.code.DreamJSONEncoder.java

License:Open Source License

@Override
protected void encode(ChannelHandlerContext ctx, String msg, ByteBuf out) throws Exception {
    //      System.out.println("begin encode");
    if (StringUtils.isEmpty(msg)) {
        return;//from w  w  w .j av a2  s .c o  m
    }
    byte[] message = msg.getBytes("UTF-8");
    out.writeInt(message.length);
    out.writeBytes(message);
    //      System.out.println("end encode");
}

From source file:com.juaby.labs.rpc.client.Rpc2ClientEncoder.java

License:Apache License

@Override
protected void encode(ChannelHandlerContext ctx, RpcMessage msg, ByteBuf out) throws Exception {
    // GIOP header
    out.writeBytes(msg.getGIOPHeader());

    // Major version
    out.writeByte(msg.getMajor());/*from   w w  w. j  a v  a 2  s . c o m*/

    // Minor version
    out.writeByte(msg.getMinor());

    // Flags
    out.writeByte(msg.getFlags());

    // Value
    out.writeByte(msg.getValue());

    // ID
    out.writeInt(msg.getId());

    // Total length
    out.writeInt(msg.getTotalLength());

    // Body length
    out.writeInt(msg.getBodyLength());

    // Body
    out.writeBytes(msg.getBody());
}

From source file:com.kaijin.AdvPowerMan.tileentities.TEChargingBench.java

License:Open Source License

@Override
protected void addUniqueDescriptionData(ByteBuf data) throws IOException {
    data.writeInt(chargeLevel);
    data.writeBoolean(doingWork);/*ww  w  .  j av a 2s  . c om*/
}

From source file:com.kaijin.AdvPowerMan.tileentities.TECommon.java

License:Open Source License

/**
 * Does the bulk of the work of creating the description packet. Performs a
 * callback to addUniqueDescriptionData. That method must be overridden.
 * We're not overriding getDescriptionPacket in this class because not all
 * of our tile entities need such packets.
 * // w ww .  j  av  a2  s. c  o  m
 * @return The completed Packet250.
 */
protected Packet createDescPacket() {
    // if (ChargingBench.isDebugging)
    // System.out.println("TE getAuxillaryInfoPacket()");
    // ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    // DataOutputStream data = new DataOutputStream(bytes);
    ByteBuf data = Unpooled.buffer();
    try {
        data.writeInt(0);
        data.writeInt(xCoord);
        data.writeInt(yCoord);
        data.writeInt(zCoord);
        addUniqueDescriptionData(data);
    } catch (IOException e) {
        FMLLog.getLogger().info("[AdvancedPowerManagement] "
                + "Server failed to create description packet. (Details: " + e.toString() + ")");
    }
    // ChannelHandler.instance.sendToPlayer(new
    // AdvPacket(bytes.toByteArray()), player);
    return new S3FPacketCustomPayload("Test", data);
}