Example usage for io.netty.buffer ByteBuf readInt

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

Introduction

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

Prototype

public abstract int readInt();

Source Link

Document

Gets a 32-bit integer at the current readerIndex and increases the readerIndex by 4 in this buffer.

Usage

From source file:de.felix_klauke.pegasus.protocol.util.ByteBufUtils.java

License:Apache License

/**
 *
 * Read an UTF-8 String from a ByteBuf.//from   ww  w.  ja v a 2 s . com
 *
 * @param byteBuf the bytebuf to read from
 * @return the String
 */
public static String readUTF8String(ByteBuf byteBuf) {
    int length = byteBuf.readInt();
    String string = byteBuf.toString(byteBuf.readerIndex(), length, Charsets.UTF_8);
    byteBuf.readerIndex(byteBuf.readerIndex() + length);
    return string;
}

From source file:de.jackwhite20.cascade.shared.pipeline.handler.PacketDecoder.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List<Object> out) throws Exception {

    int length = byteBuf.readInt();

    // Allow packets with no data
    if (length > 0) {
        byte id = byteBuf.readByte();

        try {//  w  ww .  j av  a2  s  .  c  o  m
            Packet packet = protocol.create(id);
            packet.read(byteBuf);

            out.add(packet);
        } catch (IllegalStateException e) {
            ctx.fireExceptionCaught(e);
        }
    }
}

From source file:de.jackwhite20.hftp.shared.packet.ListDirectoryPacket.java

License:Open Source License

@Override
public void read(ByteBuf byteBuf) throws Exception {

    int size = byteBuf.readInt();
    for (int i = 0; i < size; i++) {
        listFileData.add(new ListFileData(readString(byteBuf), byteBuf.readFloat(), readString(byteBuf),
                byteBuf.readBoolean()));
    }//  w w  w. ja  va 2 s. co  m
}

From source file:de.jackwhite20.japs.shared.pipeline.handler.JSONObjectDecoder.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> out)
        throws Exception {

    byteBuf.readInt();
    out.add(new JSONObject(byteBuf.toString(CharsetUtil.UTF_8)));
}

From source file:de.sanandrew.mods.betterboat.network.PacketSendBoatPos.java

License:Creative Commons License

@Override
public void fromBytes(ByteBuf buf) {
    this.boatId = buf.readInt();
    this.posX = buf.readDouble();
    this.posY = buf.readDouble();
    this.posZ = buf.readDouble();
    this.rotationYaw = buf.readFloat();
    this.rotationPitch = buf.readFloat();
}

From source file:de.sanandrew.mods.turretmod.entity.projectile.EntityTurretProjectile.java

License:Creative Commons License

@Override
public void readSpawnData(ByteBuf buffer) {
    this.rotationYaw = buffer.readFloat();
    this.rotationPitch = buffer.readFloat();

    if (buffer.readBoolean()) {
        this.shooterCache = this.world.getEntityByID(buffer.readInt());
    }/*from ww w. j av a 2  s.  co  m*/
    if (buffer.readBoolean()) {
        this.targetCache = this.world.getEntityByID(buffer.readInt());
    }
}

From source file:de.sanandrew.mods.turretmod.network.PacketAssemblyToggleAutomate.java

License:Creative Commons License

@Override
public void fromBytes(ByteBuf buf) {
    this.pos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
}

From source file:de.sanandrew.mods.turretmod.network.PacketInitAssemblyCrafting.java

License:Creative Commons License

@Override
public void fromBytes(ByteBuf buf) {
    this.pos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
    this.crfUUID = ByteBufUtils.readUTF8String(buf);
    this.count = buf.readByte();
}

From source file:de.sanandrew.mods.turretmod.network.PacketOpenGui.java

License:Creative Commons License

@Override
public void fromBytes(ByteBuf buf) {
    this.guiId = buf.readByte();
    this.x = buf.readInt();
    this.y = buf.readInt();
    this.z = buf.readInt();
}

From source file:de.sanandrew.mods.turretmod.network.PacketPlayerTurretAction.java

License:Creative Commons License

@Override
public void fromBytes(ByteBuf buf) {
    this.turretId = buf.readInt();
    this.actionId = buf.readByte();
}