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.projectzed.mod.handler.message.MessageTileEntityFluidTank.java

License:Open Source License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(this.x);
    buf.writeInt(this.y);
    buf.writeInt(this.z);
    buf.writeByte(this.tier);
    buf.writeInt(this.fluidAmount);
    buf.writeInt(this.fluidID);
}

From source file:com.quavo.osrs.network.protocol.codec.update.UpdateEncoder.java

License:Open Source License

@Override
protected void encode(ChannelHandlerContext ctx, UpdateResponse msg, ByteBuf out) throws Exception {
    int type = msg.getType();
    int id = msg.getId();
    ByteBuf container = msg.getContainer();

    int compression = container.readUnsignedByte();
    int length = container.readInt();

    out.writeByte(type);/*from   w ww.  j  av a  2s .c o  m*/
    out.writeShort(id);
    out.writeByte(compression);
    out.writeInt(length);

    int bytes = container.readableBytes();
    if (bytes > 504) {
        bytes = 504;
    }
    out.writeBytes(container.readBytes(bytes));
    while ((bytes = container.readableBytes()) != 0) {
        if (bytes == 0) {
            break;
        } else if (bytes > 511) {
            bytes = 511;
        }
        out.writeByte(0xff);
        out.writeBytes(container.readBytes(bytes));
    }
}

From source file:com.rs3e.network.protocol.codec.js5.UpdateEncoder.java

License:Open Source License

@Override
public void encode(ChannelHandlerContext ctx, FileResponse response, ByteBuf buf) throws Exception {
    ByteBuf container = response.getContainer();
    int type = response.getType();
    int file = response.getFile();

    int compression = container.readUnsignedByte();
    int size = ((container.readByte() & 0xff) << 24) + ((container.readByte() & 0xff) << 16)
            + ((container.readByte() & 0xff) << 8) + (container.readByte() & 0xff);
    if (!response.isPriority()) {
        file |= 0x80000000;//from www.  j a  va2s.c o m
    }

    buf.writeByte(type);
    buf.writeInt(file);
    buf.writeByte(compression);
    buf.writeInt(size);

    int bytes = container.readableBytes();
    if (bytes > 502) {
        bytes = 502;
    }

    buf.writeBytes(container.readBytes(bytes));

    for (;;) {
        bytes = container.readableBytes();
        if (bytes == 0) {
            break;
        } else if (bytes > 507) {
            bytes = 507;
        }
        buf.writeByte(type);
        buf.writeInt(file);
        buf.writeBytes(container.readBytes(bytes));

    }
}

From source file:com.rs3e.network.protocol.codec.js5.UpdateStatusEncoder.java

License:Open Source License

@Override
public void encode(ChannelHandlerContext ctx, UpdateStatusMessage msg, ByteBuf out) throws Exception {
    for (int i = 0; i < UPDATE_DATA.length; i++)
        out.writeInt(UPDATE_DATA[i]);
    out.writeByte(msg.getStatus());/*from w  w  w .ja v a2s  .c om*/
}

From source file:com.rs3e.network.protocol.worldlist.WorldListEncoder.java

License:Open Source License

@Override
public void encode(ChannelHandlerContext ctx, WorldListMessage list, ByteBuf out) throws Exception {
    ByteBuf buf = Unpooled.buffer();
    buf.writeByte(1);//  w  w  w.  j  a  va  2s . co  m
    buf.writeByte(1);

    Country[] countries = list.getCountries();
    ByteBufUtils.writeSmart(buf, countries.length);
    for (Country country : countries) {
        ByteBufUtils.writeSmart(buf, country.getFlag());
        ByteBufUtils.writeWorldListString(buf, country.getName());
    }

    World[] worlds = list.getWorlds();
    int minId = worlds[0].getId();
    int maxId = worlds[0].getId();
    for (int i = 1; i < worlds.length; i++) {
        World world = worlds[i];
        int id = world.getId();

        if (id > maxId)
            maxId = id;
        if (id < minId)
            minId = id;
    }

    ByteBufUtils.writeSmart(buf, minId);
    ByteBufUtils.writeSmart(buf, maxId);
    ByteBufUtils.writeSmart(buf, worlds.length);

    for (World world : worlds) {
        ByteBufUtils.writeSmart(buf, world.getId() - minId);
        buf.writeByte(world.getCountry());
        buf.writeInt(world.getFlags());
        ByteBufUtils.writeWorldListString(buf, world.getActivity());
        ByteBufUtils.writeWorldListString(buf, world.getIp());
    }

    buf.writeInt(list.getSessionId());
    for (int i = 0; i < worlds.length; i++) {
        World world = worlds[i];
        ByteBufUtils.writeSmart(buf, world.getId() - minId);
        buf.writeShort(0);
    }

    out.writeByte(0); // 0 = ok, 7/9 = world full
    out.writeShort(buf.readableBytes());
    out.writeBytes(buf);
}

From source file:com.savageboy74.savagetech.network.message.MessageTileEntityBase.java

License:Open Source License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(x);
    buf.writeInt(y);/* w ww  .j  a v  a2 s.  co m*/
    buf.writeInt(z);
    buf.writeByte(orientation);
    buf.writeByte(state);
    buf.writeInt(customName.length());
    buf.writeBytes(customName.getBytes());
    buf.writeInt(owner.length());
    buf.writeBytes(owner.getBytes());
}

From source file:com.seagate.kinetic.common.protocol.codec.KineticEncoder.java

License:Open Source License

@Override
protected void encode(ChannelHandlerContext ctx, KineticMessage km, ByteBuf out) throws Exception {

    try {//from  w ww.ja v a2 s . c  o m

        // get value to write separately
        // byte[] value = builder.getValue().toByteArray();
        byte[] value = km.getValue();

        // 1. write magic number
        out.writeByte((byte) 'F');

        //get message
        Message.Builder messageBuilder = (Builder) km.getMessage();

        // build message
        Message msg = messageBuilder.build();

        // get proto message bytes
        byte[] protoMessageBytes = msg.toByteArray();

        // 2. write protobuf message message size, 4 byte
        out.writeInt(protoMessageBytes.length);

        // 3. write attached value size, 4 byte
        if (value != null) {
            out.writeInt(value.length);
        } else {
            out.writeInt(0);
        }

        // 4. write protobuf message byte[]
        out.writeBytes(protoMessageBytes);

        // 5 (optional) write attached value if any
        if (value != null && value.length > 0) {
            // write value
            out.writeBytes(value);
        }

        // log message out
        if (printMessage) {

            logger.info("outbound protocol message:");

            String printMsg = ProtocolMessageUtil.toString(km);

            logger.info(printMsg);
        }

    } catch (Exception e) {
        logger.log(Level.WARNING, e.getMessage(), e);
        throw e;
    }
}

From source file:com.seventh_root.ld33.common.network.packet.clientbound.PlayerInformationClientBoundPacket.java

License:Apache License

@Override
public void write(ByteBuf buf) throws UnsupportedEncodingException {
    super.write(buf);
    writeString(buf, getPlayerUUID().toString());
    writeString(buf, getPlayerName());//ww  w.  ja v  a 2  s.  c  o  m
    buf.writeInt(getPlayerResources());
}

From source file:com.seventh_root.ld33.common.network.packet.clientbound.PublicKeyClientBoundPacket.java

License:Apache License

@Override
public void write(ByteBuf buf) throws UnsupportedEncodingException {
    super.write(buf);
    buf.writeInt(getEncodedPublicKey().length);
    buf.writeBytes(getEncodedPublicKey());
}

From source file:com.seventh_root.ld33.common.network.packet.clientbound.UnitMoveClientBoundPacket.java

License:Apache License

@Override
public void write(ByteBuf buf) throws UnsupportedEncodingException {
    super.write(buf);
    writeString(buf, getUnitUUID().toString());
    buf.writeInt(getX());
    buf.writeInt(getY());/*w  ww.  j a  v  a2 s .c  o  m*/
    buf.writeInt(getTargetX());
    buf.writeInt(getTargetY());
}