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.github.spapageo.jannel.transcode.TranscoderHelperTest.java

License:Open Source License

@Test
public void testEncodeAdminEncodesCorrectly() throws Exception {
    Admin admin = new Admin();
    admin.setAdminCommand(AdminCommand.IDENTIFY);
    admin.setBoxId("");
    ByteBuf byteBuf = Unpooled.buffer();
    transcoderHelper.encodeAdmin(admin, byteBuf);

    assertEquals("Type of admin command is incorrect", AdminCommand.IDENTIFY,
            AdminCommand.fromValue(byteBuf.readInt()));
    assertEquals("Box name is incorrect", "",
            ChannelBufferUtils.readOctetStringToString(byteBuf, Charsets.UTF_8));
    byteBuf.release();//from  www  .j a va  2  s .c o m
}

From source file:com.github.spapageo.jannel.transcode.TranscoderHelperTest.java

License:Open Source License

@Test
public void testEncodeSmsEncodesCorrectly() throws Exception {
    byte[] data = { 0x25 };
    ByteBuf udh = Unpooled.copiedBuffer(data);
    Sms sms = new Sms();
    sms.setSender("from");
    sms.setReceiver("to");
    sms.setUdhData(udh);/*w w  w.  ja v a  2  s.  c  o  m*/
    sms.setMsgData("content");
    sms.setTime(0);
    sms.setSmscId("smsc");
    sms.setSmscNumber("smscNumber");
    sms.setForeignId("foreignId");
    sms.setService("service");
    sms.setAccount("account");
    sms.setId(UUID.randomUUID());
    sms.setSmsType(SmsType.MOBILE_TERMINATED_REPLY);
    sms.setMessageClass(MessageClass.MC_CLASS2);
    sms.setMwi(MessageWaitingIndicator.fromValue(3));
    sms.setCoding(DataCoding.fromValue(2));
    sms.setCompress(Compress.fromValue(1));
    sms.setValidity(6);
    sms.setDeferred(7);
    sms.setDlrMask(8);
    sms.setDlrUrl("dlrUrl");
    sms.setPid(9);
    sms.setAltDcs(10);
    sms.setRpi(ReturnPathIndicator.fromValue(1));
    sms.setCharset(Charsets.UTF_8);
    sms.setBoxId("box");
    sms.setBillingInfo("binfo");
    sms.setMsgLeft(12);
    sms.setPriority(13);
    sms.setResendTry(14);
    sms.setResendTime(15);
    sms.setMetaData("metadata");
    ByteBuf byteBuf = Unpooled.buffer();
    transcoderHelper.encodeSms(sms, byteBuf);

    assertEquals("The  from is incorrect", "from",
            ChannelBufferUtils.readOctetStringToString(byteBuf, Charsets.UTF_8));
    assertEquals("The to is incorrect", "to",
            ChannelBufferUtils.readOctetStringToString(byteBuf, Charsets.UTF_8));
    assertEquals("The udhdata is incorrect", udh.readerIndex(0),
            ChannelBufferUtils.readOctetStringToBytes(byteBuf));
    assertEquals("The message data is incorrect", "content",
            ChannelBufferUtils.readOctetStringToString(byteBuf, Charsets.UTF_8));

    assertEquals("The time is incorrect", 0, byteBuf.readInt());
    assertEquals("The smsc is incorrect", "smsc",
            ChannelBufferUtils.readOctetStringToString(byteBuf, Charsets.UTF_8));
    assertEquals("The smscNumber is incorrect", "smscNumber",
            ChannelBufferUtils.readOctetStringToString(byteBuf, Charsets.UTF_8));
    assertEquals("The foreignId is incorrect", "foreignId",
            ChannelBufferUtils.readOctetStringToString(byteBuf, Charsets.UTF_8));
    assertEquals("The service is incorrect", "service",
            ChannelBufferUtils.readOctetStringToString(byteBuf, Charsets.UTF_8));
    assertEquals("The account is incorrect", "account",
            ChannelBufferUtils.readOctetStringToString(byteBuf, Charsets.UTF_8));
    assertEquals("The id is incorrect", sms.getId(), ChannelBufferUtils.readUUID(byteBuf, Charsets.UTF_8));
    assertEquals("The sms type is incorrect", sms.getSmsType(), SmsType.fromValue(byteBuf.readInt()));
    assertEquals("The m class is incorrect", 2, byteBuf.readInt());
    assertEquals("The mwi is incorrect", 3, byteBuf.readInt());
    assertEquals("The coding is incorrect", 2, byteBuf.readInt());
    assertEquals("The compress is incorrect", 1, byteBuf.readInt());
    assertEquals("The validity is incorrect", 6, byteBuf.readInt());
    assertEquals("The deferred is incorrect", 7, byteBuf.readInt());
    assertEquals("The dlr mask is incorrect", 8, byteBuf.readInt());
    assertEquals("The dlr url is incorrect", "dlrUrl",
            ChannelBufferUtils.readOctetStringToString(byteBuf, Charsets.UTF_8));

    assertEquals("The pid is incorrect", 9, byteBuf.readInt());
    assertEquals("The alt dcs is incorrect", 10, byteBuf.readInt());
    assertEquals("The rpi is incorrect", 1, byteBuf.readInt());
    assertEquals("The charset is incorrect", "UTF-8",
            ChannelBufferUtils.readOctetStringToString(byteBuf, Charsets.UTF_8));
    assertEquals("The box id is incorrect", "box",
            ChannelBufferUtils.readOctetStringToString(byteBuf, Charsets.UTF_8));
    assertEquals("The binfo is incorrect", "binfo",
            ChannelBufferUtils.readOctetStringToString(byteBuf, Charsets.UTF_8));

    assertEquals("The msgLeft is incorrect", 12, byteBuf.readInt());
    assertEquals("The priority is incorrect", 13, byteBuf.readInt());
    assertEquals("The resend try is incorrect", 14, byteBuf.readInt());
    assertEquals("The resend time is incorrect", 15, byteBuf.readInt());
    assertEquals("The meta data is incorrect", "metadata",
            ChannelBufferUtils.readOctetStringToString(byteBuf, Charsets.UTF_8));
    udh.release();
}

From source file:com.github.sparkfy.network.protocol.OneWayMessage.java

License:Apache License

public static OneWayMessage decode(ByteBuf buf) {
    // See comment in encodedLength().
    buf.readInt();
    return new OneWayMessage(new NettyManagedBuffer(buf.retain()));
}

From source file:com.github.sparkfy.network.protocol.RpcRequest.java

License:Apache License

public static RpcRequest decode(ByteBuf buf) {
    long requestId = buf.readLong();
    // See comment in encodedLength().
    buf.readInt();
    return new RpcRequest(requestId, new NettyManagedBuffer(buf.retain()));
}

From source file:com.github.sparkfy.network.protocol.RpcResponse.java

License:Apache License

public static RpcResponse decode(ByteBuf buf) {
    long requestId = buf.readLong();
    // See comment in encodedLength().
    buf.readInt();
    return new RpcResponse(requestId, new NettyManagedBuffer(buf.retain()));
}

From source file:com.github.sparkfy.network.protocol.StreamChunkId.java

License:Apache License

public static StreamChunkId decode(ByteBuf buffer) {
    assert buffer.readableBytes() >= 8 + 4;
    long streamId = buffer.readLong();
    int chunkIndex = buffer.readInt();
    return new StreamChunkId(streamId, chunkIndex);
}

From source file:com.gmail.socraticphoenix.forge.randore.packet.RandoresSeedPacket.java

License:Open Source License

@Override
public void fromBytes(ByteBuf buf) {
    this.setSeed(buf.readLong()).setOreCount(buf.readInt());
}

From source file:com.grillecube.common.resources.PacketManager.java

/** Returns an instance of a packet from byteBuffer */
public Packet fromByteBuffer(ByteBuf byteBuffer) throws NoSuchPacketException, WrongPacketFormatException {
    return (this.getFromPacketID(byteBuffer.readInt(), byteBuffer));
}

From source file:com.hazelcast.simulator.protocol.core.ResponseCodec.java

License:Open Source License

public static Response decodeResponse(ByteBuf buffer) {
    int frameLength = buffer.readInt();
    int dataLength = (frameLength - HEADER_SIZE) / DATA_ENTRY_SIZE;

    if (buffer.readInt() != MAGIC_BYTES) {
        throw new IllegalArgumentException("Invalid magic bytes for Response");
    }/*from  www  . ja  v  a 2  s .c  o  m*/

    long messageId = buffer.readLong();
    SimulatorAddress destination = decodeSimulatorAddress(buffer);
    Response response = new Response(messageId, destination);

    for (int i = 0; i < dataLength; i++) {
        SimulatorAddress source = decodeSimulatorAddress(buffer);
        ResponseType responseType = ResponseType.fromInt(buffer.readInt());
        response.addResponse(source, responseType);
    }

    return response;
}

From source file:com.hazelcast.simulator.protocol.core.SimulatorAddressCodec.java

License:Open Source License

static SimulatorAddress decodeSimulatorAddress(ByteBuf buffer) {
    return new SimulatorAddress(AddressLevel.fromInt(buffer.readInt()), buffer.readInt(), buffer.readInt(),
            buffer.readInt());//from   w w  w  . ja v a 2 s  . co  m
}