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:dbseer.middleware.packet.MiddlewarePacketDecoder.java

License:Apache License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
    if (buf.readableBytes() < 8) {
        Log.debug(this.getClass().getCanonicalName(), "buf less than 8 bytes");
        return;// w  ww.j a v  a  2s. c  om
    }

    buf.markReaderIndex();
    int header = buf.readInt();
    int length = buf.readInt();

    if (buf.readableBytes() < length) {
        buf.resetReaderIndex();
        Log.debug(this.getClass().getCanonicalName(),
                "readable bytes less than length = " + length + " and header = " + header);
        return;
    }
    String log = "";
    Log.debug(String.format("len = %d, readable = %d", length, buf.readableBytes()));

    if (length > 0) {
        byte[] readBuf = new byte[length];
        buf.readBytes(readBuf);
        log = new String(readBuf, "UTF-8");
    }

    out.add(new MiddlewarePacket(header, length, log));
}

From source file:de.canitzp.rarmor.packet.PacketOpenConfirmation.java

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

From source file:de.canitzp.rarmor.packet.PacketOpenModule.java

@Override
public void fromBytes(ByteBuf buf) {
    this.moduleId = buf.readInt();
    this.alsoSetData = buf.readBoolean();
    this.sendRarmorDataToClient = buf.readBoolean();
}

From source file:de.canitzp.rarmor.packet.PacketSyncRarmorData.java

@Override
public void fromBytes(ByteBuf buf) {
    this.shouldReloadTabs = buf.readBoolean();
    this.moduleIdForConfirmation = buf.readInt();

    try {//from   w w w .  j  av  a  2  s.c o  m
        PacketBuffer buffer = new PacketBuffer(buf);

        this.stackId = buffer.readUniqueId();
        this.receivedDataCompound = buffer.readCompoundTag();
    } catch (IOException e) {
        Rarmor.LOGGER.info("Something went wrong trying to receive a " + Rarmor.MOD_NAME + " Update Packet!",
                e);
    }
}

From source file:de.ellpeck.actuallyadditions.mod.network.gui.PacketGuiButton.java

@Override
public void fromBytes(ByteBuf buf) {
    this.tileX = buf.readInt();
    this.tileY = buf.readInt();
    this.tileZ = buf.readInt();
    this.worldID = buf.readInt();
    this.buttonID = buf.readInt();
    this.playerID = buf.readInt();
}

From source file:de.ellpeck.actuallyadditions.mod.network.gui.PacketGuiNumber.java

@Override
public void fromBytes(ByteBuf buf) {
    this.tileX = buf.readInt();
    this.tileY = buf.readInt();
    this.tileZ = buf.readInt();
    this.worldID = buf.readInt();
    this.text = buf.readInt();
    this.textID = buf.readInt();
    this.playerID = buf.readInt();
}

From source file:de.ellpeck.actuallyadditions.mod.network.gui.PacketGuiString.java

@Override
public void fromBytes(ByteBuf buf) {
    this.tileX = buf.readInt();
    this.tileY = buf.readInt();
    this.tileZ = buf.readInt();
    this.worldID = buf.readInt();

    this.text = "";
    int textLength = buf.readInt();
    for (int i = 0; i < textLength; i++) {
        this.text += buf.readChar();
    }/*  www .  j  av a2 s  .  c  o m*/

    this.textID = buf.readInt();
    this.playerID = buf.readInt();
}

From source file:de.ellpeck.actuallyadditions.mod.network.PacketParticle.java

@Override
public void fromBytes(ByteBuf buf) {
    this.startX = buf.readDouble();
    this.startY = buf.readDouble();
    this.startZ = buf.readDouble();
    this.endX = buf.readDouble();
    this.endY = buf.readDouble();
    this.endZ = buf.readDouble();
    this.particleAmount = buf.readInt();
    this.particleSize = buf.readFloat();

    this.color = new float[3];
    for (int i = 0; i < this.color.length; i++) {
        this.color[i] = buf.readFloat();
    }//w w  w  .  j  av a  2 s .c  om
}

From source file:de.felix_klauke.pegasus.protocol.decoder.PacketDecoder.java

License:Apache License

/**
 * This method will handle any incoming data. Neverminds about the type.
 *
 * @param channelHandlerContext the contect of the Channel the data comes from
 * @param byteBuf               the incoming data
 * @param list                  add all objects to continue to work with to this list
 * @throws Exception will be thrown when handling the data fails
 *///from   w w w.j a  v  a  2  s .  co m
@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list)
        throws Exception {
    if (byteBuf instanceof EmptyByteBuf)
        return;
    int packetID = byteBuf.readInt();

    if (packetID == -1) {
        throw new UnsupportedMessageTypeException();
    }
    Packet packet = PacketType.lookup(packetID);
    if (packet != null) {
        packet.decode(byteBuf);
        list.add(packet);
    }
}

From source file:de.felix_klauke.pegasus.protocol.packets.PacketHandshakeResponse.java

License:Apache License

/**
 *
 * @param byteBuf the bytebof to decode the packet from
 *///from  w ww.jav  a 2  s. c  o  m
@Override
public void decode(ByteBuf byteBuf) {
    result = HandshakeResult.lookup(byteBuf.readInt());
}