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:com.ns.netty.gcd.server.BigIntegerDecoder.java

License:Apache License

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

    System.out.println("Decoder received event");

    // Wait until the length prefix is available.
    if (in.readableBytes() < 5) {
        return;/*from  ww w  . j a  v  a2s .c o  m*/
    }

    in.markReaderIndex();

    // Check the magic number.
    int magicNumber = in.readUnsignedByte();
    if (magicNumber != 'F') {
        in.resetReaderIndex();
        throw new CorruptedFrameException("Invalid magic number: " + magicNumber);
    }

    // Wait until the whole data is available.
    int dataLength = in.readInt();
    if (in.readableBytes() < dataLength) {
        in.resetReaderIndex();
        return;
    }

    // Convert the received data into a new BigInteger.
    byte[] decoded = new byte[dataLength];
    in.readBytes(decoded);

    out.add(new BigInteger(decoded));
}

From source file:com.ogarproject.ogar.server.net.packet.inbound.PacketInAuthenticate.java

License:Open Source License

@Override
public void readData(ByteBuf buf) {
    this.protocolVersion = buf.readInt();
}

From source file:com.ogarproject.ogar.server.net.packet.inbound.PacketInMouseMove.java

License:Open Source License

@Override
public void readData(ByteBuf buf) {
    x = buf.readInt();
    y = buf.readInt();
    nodeId = buf.readInt();
}

From source file:com.ogarproject.ogar.server.net.packet.inbound.PacketInResetConnection.java

License:Open Source License

@Override
public void readData(ByteBuf buf) {
    magic = buf.readInt();
}

From source file:com.parachute.common.KeyPressMessage.java

License:Open Source License

@Override
public void fromBytes(ByteBuf bb) {
    keyCode = bb.readInt();
    keyPressed = bb.readBoolean();
}

From source file:com.phei.netty.protocol.netty.codec.NettyMessageDecoder.java

License:Apache License

@Override
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
    //LengthFieldBasedFrameDecoder??
    //???/*www.  j a v  a2  s  .  c o m*/
    //i/o????
    ByteBuf frame = (ByteBuf) super.decode(ctx, in);
    if (frame == null) {
        return null;
    }

    NettyMessage message = new NettyMessage();
    Header header = new Header();
    header.setCrcCode(frame.readInt());
    header.setLength(frame.readInt());
    header.setSessionID(frame.readLong());
    header.setType(frame.readByte());
    header.setPriority(frame.readByte());

    int size = frame.readInt();
    if (size > 0) {
        Map<String, Object> attch = new HashMap<String, Object>(size);
        int keySize = 0;
        byte[] keyArray = null;
        String key = null;
        for (int i = 0; i < size; i++) {
            keySize = frame.readInt();
            keyArray = new byte[keySize];
            frame.readBytes(keyArray);
            key = new String(keyArray, "UTF-8");
            attch.put(key, marshallingDecoder.decode(frame));
        }
        keyArray = null;
        key = null;
        header.setAttachment(attch);
    }
    //body??body
    if (frame.readableBytes() > 4) {
        message.setBody(marshallingDecoder.decode(frame));
    }
    message.setHeader(header);
    return message;
}

From source file:com.professorvennie.machinerycraft.core.network.MessageButton.java

License:Creative Commons License

@Override
public void fromBytes(ByteBuf buf) {
    super.fromBytes(buf);
    id = buf.readInt();
}

From source file:com.projectzed.mod.handler.message.MessageTileEntityFluidTank.java

License:Open Source License

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

From source file:com.quavo.osrs.game.model.entity.actor.player.info.LoginClearance.java

License:Open Source License

/**
 * Reads the data from a {@link ByteBuf} for a login clearance.
 * //from w w  w .  ja v a 2s  . c om
 * @param buffer The {@link ByteBuf}.
 */
public void readNoReturn(ByteBuf buffer) {
    switch (this) {
    case NORMAL:
        buffer.readerIndex(buffer.readerIndex() + 8);
        break;
    case TRUSTED_COMPUTER:
        buffer.readInt();
        buffer.readerIndex(buffer.readerIndex() + 4);
        break;
    case AUTHENTICATOR:
    case TRUSTED_AUTHENTICATOR:
        buffer.readMedium();
        buffer.readerIndex(buffer.readerIndex() + 5);
        break;
    }
}

From source file:com.quavo.osrs.game.model.entity.actor.player.info.LoginClearance.java

License:Open Source License

/**
 * Reads the data from a {@link ByteBuf} for a login clearance.
 * /*w  ww  .ja  v a2s . c o  m*/
 * @param buffer The {@link ByteBuf}.
 * @return The created login clearance type.
 */
public LoginClearance read(ByteBuf buffer) {
    switch (this) {
    case NORMAL:
        buffer.readerIndex(buffer.readerIndex() + 8);
        break;
    case TRUSTED_COMPUTER:
        buffer.readInt();
        buffer.readerIndex(buffer.readerIndex() + 4);
        break;
    case AUTHENTICATOR:
    case TRUSTED_AUTHENTICATOR:
        buffer.readMedium();
        buffer.readerIndex(buffer.readerIndex() + 5);
        break;
    }
    return this;
}