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.friz.owari.network.codec.ExchangeDecoder.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    if (!in.isReadable())
        return;//from www .  ja  v  a 2  s .c  o m

    int len = in.readInt();
    byte[] enc = new byte[len];
    in.readBytes(enc);

    out.add(new ExchangeRecieveEvent(enc));
}

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

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    if (!in.isReadable())
        return;/*from  w w w .j  a  va2 s  .c o  m*/

    int length = in.readUnsignedShort();
    byte[] path = new byte[length];
    in.readBytes(path);

    int size = in.readInt();
    byte[] bytes = new byte[size];
    in.readBytes(bytes);

    out.add(new PatchEvent(new String(path), bytes));
}

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

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    if (!in.isReadable())
        return;//from ww  w  .  j a  v  a 2s .  c o  m

    int count = in.readInt();
    long size = in.readLong();
    out.add(new PatchInitEvent(count, size));
}

From source file:com.friz.update.network.codec.UpdateDecoder.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
    if (!buffer.isReadable(6))
        return;/*from  w w  w.ja v  a  2 s .c  o  m*/

    int opcode = buffer.readUnsignedByte();
    if (opcode == 0 || opcode == 1) {
        int type = buffer.readUnsignedByte();
        int file = buffer.readInt();
        out.add(new FileRequestEvent(opcode == 1, type, file));
    } else if (opcode == 4) {
        int key = buffer.readUnsignedByte();
        buffer.readerIndex(buffer.readerIndex() + 4);
        out.add(new XorRequestEvent(key));
    } else {
        buffer.readerIndex(buffer.readerIndex() + 5);
    }
}

From source file:com.friz.update.network.codec.UpdateInitDecoder.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
    int type = buf.readUnsignedByte();
    int size = buf.readUnsignedByte();

    if (!buf.isReadable(size))
        return;/*from ww w. j a va  2  s.  c om*/

    int version = buf.readInt();
    int subVersion = buf.readInt();
    String key = BufferUtils.getString(buf);
    int langId = buf.readUnsignedByte();
    out.add(new UpdateRequestEvent(type, version, subVersion, key, langId));
}

From source file:com.github.milenkovicm.kafka.protocol.Convert.java

License:Apache License

public static int decodeInteger(ByteBuf buf) {
    return buf.readInt();
}

From source file:com.github.pgasync.impl.netty.ByteBufMessageDecoder.java

License:Apache License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    if (in.readableBytes() == 0) {
        return;/*from w  w w . ja va  2s.c o  m*/
    }

    byte id = in.readByte();
    int length = in.readInt();

    Decoder<?> decoder = DECODERS.get(id);
    try {
        if (decoder != null) {
            ByteBuffer buffer = in.nioBuffer();
            out.add(decoder.read(buffer));
            in.skipBytes(buffer.position());
        } else {
            in.skipBytes(length - 4);
        }
    } catch (Throwable t) {
        // broad catch as otherwise the exception is silently dropped
        ctx.fireExceptionCaught(t);
    }
}

From source file:com.github.spapageo.jannel.channel.ChannelBufferUtils.java

License:Open Source License

/**
 * Reads a new octet string from the byte buffer using the UTF-8 encoding
 * @param byteBuffer the bytes to read the string from
 * @param charset    the charset to use in order to decode the string
 * @return the created string//from   w  w w . j a v  a2  s. c o  m
 */
@Nonnull
public static String readOctetStringToString(ByteBuf byteBuffer, Charset charset) {

    if (byteBuffer.readableBytes() < 4)
        throw new NotEnoughDataDecoderException("Not enough bytes to read the octet string size");

    int stringSize = byteBuffer.readInt();

    checkOctetStringSize(byteBuffer, stringSize);

    if (stringSize == -1)
        return EMPTY_STRING;

    return byteBuffer.readSlice(stringSize).toString(charset);
}

From source file:com.github.spapageo.jannel.channel.ChannelBufferUtils.java

License:Open Source License

/**
 * Read a 4 byte integer from the byte buffer
 * @param byteBuffer the bytes to read from
 * @return the integer//from   w w  w .  j ava  2  s  . c o  m
 */
public static int readInt(ByteBuf byteBuffer) {
    if (byteBuffer.readableBytes() < 4)
        throw new NotEnoughDataDecoderException("Not enough bytes to read the integer");

    return byteBuffer.readInt();
}

From source file:com.github.spapageo.jannel.channel.ChannelBufferUtils.java

License:Open Source License

/**
 * Reads a data segment from the byte buffer
 * @param byteBuffer the bytes to read from
 * @return the data segment//from   w w w .j a  va  2  s.  co m
 */
@Nonnull
public static ByteBuf readOctetStringToBytes(ByteBuf byteBuffer) {
    if (byteBuffer.readableBytes() < 4)
        throw new NotEnoughDataDecoderException("Not enough bytes to read the octet string size");

    int dataSize = byteBuffer.readInt();

    if (dataSize == -1)
        return Unpooled.EMPTY_BUFFER;

    checkOctetStringSize(byteBuffer, dataSize);

    return byteBuffer.readBytes(dataSize);
}