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.flowpowered.examples.networking.TestProtocol.java

License:MIT License

@Override
public ByteBuf writeHeader(ByteBuf header, CodecRegistration codec, ByteBuf data) {
    header.writeShort(codec.getOpcode());
    header.writeInt(data.writerIndex());
    return header;
}

From source file:com.flowpowered.examples.networking.TestSecondProtocol.java

License:MIT License

@Override
public ByteBuf writeHeader(ByteBuf header, Codec.CodecRegistration codec, ByteBuf data) {
    header.writeShort(codec.getOpcode());
    header.writeInt(data.writerIndex());
    return header;
}

From source file:com.foilen.smalltools.net.commander.channel.CommanderEncoder.java

License:Open Source License

@Override
protected void encode(ChannelHandlerContext ctx, CommandRequest msg, ByteBuf out) throws Exception {

    String className = msg.commandImplementationClass();

    logger.debug("Encoding message of type {} to call the implementation {}", msg.getClass().getName(),
            className);/*from  ww w.  ja va 2s . c o m*/

    try {
        byte[] classNameBytes = className.getBytes(CharsetTools.UTF_8);
        String jsonContent = JsonTools.writeToString(msg);
        byte[] jsonContentBytes = jsonContent.getBytes(CharsetTools.UTF_8);

        out.writeInt(classNameBytes.length);
        out.writeBytes(classNameBytes);

        out.writeInt(jsonContentBytes.length);
        out.writeBytes(jsonContentBytes);
    } catch (Exception e) {
        logger.warn("Problem encoding the message", e);
    }

}

From source file:com.forgetutorials.lib.network.SubPacketTileEntityCustom.java

License:LGPL

@Override
public void writeData(ByteBuf data) throws IOException {
    data.writeInt(this.custom.writerIndex());
    data.writeBytes(this.custom);
}

From source file:com.forgetutorials.lib.network.SubPacketTileEntityFluidUpdate.java

License:LGPL

@Override
public void writeData(ByteBuf data) throws IOException {
    data.writeInt(this.position);
    NBTTagCompound tag = new NBTTagCompound();
    if (this.fluid != null) {
        this.fluid.writeToNBT(tag);
        tag.setBoolean("null", false);
    } else {/* ww w .j a v a  2  s.com*/
        tag.setBoolean("null", true);
    }
    ByteBufUtils.writeTag(data, tag);
}

From source file:com.forgetutorials.lib.network.SubPacketTileEntitySimpleItemUpdate.java

License:LGPL

@Override
public void writeData(ByteBuf data) throws IOException {
    data.writeInt(this.position);
    ByteBufUtils.writeItemStack(data, this.item);
}

From source file:com.friz.network.utility.BufferUtils.java

License:Open Source License

/**
 * Puts a 5 byte integer into the buffer.
 * @param buf The channel buffer/*w w  w . j  a  v  a 2s  .c  o  m*/
 * @param value The value to be added.
 */
public static void put5ByteInteger(ByteBuf buf, long value) {
    buf.writeByte((int) (value >> 32));
    buf.writeInt((int) (value));
}

From source file:com.friz.network.utility.BufferUtils.java

License:Open Source License

/**
 * Puts a 6 byte integer into the buffer.
 * @param buf The channel buffer/*from w w  w.j av a  2s .c o  m*/
 * @param value The value to be added.
 */
public static void put6ByteInteger(ByteBuf buf, long value) {
    buf.writeShort((int) (value >> 32));
    buf.writeInt((int) (value));
}

From source file:com.friz.owari.network.codec.ExchangeEncoder.java

License:Open Source License

@Override
protected void encode(ChannelHandlerContext ctx, ExchangeTransferEvent msg, ByteBuf out) throws Exception {
    if (!out.isWritable())
        return;//from  ww  w  .  ja v a 2  s . co m

    final PublicKey key = msg.getPublicKey();

    byte[] enc = key.getEncoded();

    out.writeInt(enc.length);
    out.writeBytes(enc);
}

From source file:com.friz.owari.network.codec.PatchInitEncoder.java

License:Open Source License

@Override
protected void encode(ChannelHandlerContext ctx, PatchInitEvent msg, ByteBuf out) throws Exception {
    if (!out.isWritable())
        return;/*  ww  w  . j a v a  2 s  .  c  o  m*/

    out.writeInt(msg.getCount());
    out.writeLong(msg.getSize());
}