Example usage for io.netty.buffer ByteBuf readableBytes

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

Introduction

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

Prototype

public abstract int readableBytes();

Source Link

Document

Returns the number of readable bytes which is equal to (this.writerIndex - this.readerIndex) .

Usage

From source file:com.cloudhopper.smpp.transcoder.PduDecoderTest.java

License:Apache License

@Test
public void decodeSequenceNumberOfOne() throws Exception {
    ByteBuf buffer = BufferHelper.createBuffer("00000010000000150000000000000001");
    EnquireLink pdu0 = (EnquireLink) transcoder.decode(buffer);
    Assert.assertEquals(1, pdu0.getSequenceNumber());
    // despite having too large a sequence number, all the bytes should have been read
    Assert.assertEquals(0, buffer.readableBytes());
}

From source file:com.cloudhopper.smpp.transcoder.PduDecoderTest.java

License:Apache License

@Test
public void decodeSequenceNumberMaxValue() throws Exception {
    ByteBuf buffer = BufferHelper.createBuffer("0000001000000015000000007fffffff");
    EnquireLink pdu0 = (EnquireLink) transcoder.decode(buffer);
    Assert.assertEquals(0x7fffffff, pdu0.getSequenceNumber());
    // despite having too large a sequence number, all the bytes should have been read
    Assert.assertEquals(0, buffer.readableBytes());
}

From source file:com.cloudhopper.smpp.transcoder.PduDecoderTest.java

License:Apache License

@Test
public void decodeEnquireLink() throws Exception {
    ByteBuf buffer = BufferHelper.createBuffer("0000001000000015000000000a342ee7");

    EnquireLink pdu0 = (EnquireLink) transcoder.decode(buffer);

    Assert.assertEquals(16, pdu0.getCommandLength());
    Assert.assertEquals(SmppConstants.CMD_ID_ENQUIRE_LINK, pdu0.getCommandId());
    Assert.assertEquals(0, pdu0.getCommandStatus());
    Assert.assertEquals(171192039, pdu0.getSequenceNumber());
    Assert.assertEquals(true, pdu0.isRequest());

    Assert.assertEquals(0, buffer.readableBytes());
}

From source file:com.cloudhopper.smpp.transcoder.PduDecoderTest.java

License:Apache License

@Test
public void decodeEnquireLinkResp() throws Exception {
    ByteBuf buffer = BufferHelper.createBuffer("0000001080000015000000000a342eed");

    EnquireLinkResp pdu0 = (EnquireLinkResp) transcoder.decode(buffer);

    Assert.assertEquals(16, pdu0.getCommandLength());
    Assert.assertEquals(SmppConstants.CMD_ID_ENQUIRE_LINK_RESP, pdu0.getCommandId());
    Assert.assertEquals(0, pdu0.getCommandStatus());
    Assert.assertEquals(171192045, pdu0.getSequenceNumber());
    Assert.assertEquals(true, pdu0.isResponse());

    Assert.assertEquals(0, buffer.readableBytes());
}

From source file:com.cloudhopper.smpp.transcoder.PduDecoderTest.java

License:Apache License

@Test
public void decodeTwoEnquireLinkRespButWithReadRequiredInBetween() throws Exception {
    // f1 missing on end at first
    ByteBuf buffer = BufferHelper
            .createBuffer("0000001080000015000000000a342eed0000001080000015000000000a342e");

    EnquireLinkResp pdu0 = (EnquireLinkResp) transcoder.decode(buffer);

    Assert.assertEquals(16, pdu0.getCommandLength());
    Assert.assertEquals(SmppConstants.CMD_ID_ENQUIRE_LINK_RESP, pdu0.getCommandId());
    Assert.assertEquals(0, pdu0.getCommandStatus());
    Assert.assertEquals(171192045, pdu0.getSequenceNumber());
    Assert.assertEquals(true, pdu0.isResponse());

    Assert.assertEquals(15, buffer.readableBytes());

    // second enquireLink response (but missing 1 byte)
    pdu0 = (EnquireLinkResp) transcoder.decode(buffer);
    Assert.assertNull(pdu0);/* w ww.  ja v  a2  s  .  c o m*/

    Assert.assertEquals(15, buffer.readableBytes());

    // add 1 more byte (should finish the byte array off)
    ByteBuf buffer0 = BufferHelper.createBuffer("f1");
    ByteBuf buffer1 = Unpooled.wrappedBuffer(buffer, buffer0); // merge both buffers...
    buffer = buffer1;

    pdu0 = (EnquireLinkResp) transcoder.decode(buffer);

    Assert.assertEquals(16, pdu0.getCommandLength());
    Assert.assertEquals(SmppConstants.CMD_ID_ENQUIRE_LINK_RESP, pdu0.getCommandId());
    Assert.assertEquals(0, pdu0.getCommandStatus());
    Assert.assertEquals(171192049, pdu0.getSequenceNumber());
    Assert.assertEquals(true, pdu0.isResponse());

    Assert.assertEquals(0, buffer.readableBytes());
}

From source file:com.cloudhopper.smpp.transcoder.PduDecoderTest.java

License:Apache License

@Test
public void decodeSubmitSmResp() throws Exception {
    ByteBuf buffer = BufferHelper.createBuffer("0000001c80000004000000000a342ee1393432353834333135393400");

    SubmitSmResp pdu0 = (SubmitSmResp) transcoder.decode(buffer);

    Assert.assertEquals(28, pdu0.getCommandLength());
    Assert.assertEquals(0x80000004, pdu0.getCommandId());
    Assert.assertEquals(0, pdu0.getCommandStatus());
    Assert.assertEquals(171192033, pdu0.getSequenceNumber());
    Assert.assertEquals(true, pdu0.isResponse());
    // messageId 94258431594
    Assert.assertEquals("94258431594", pdu0.getMessageId());

    Assert.assertEquals(0, buffer.readableBytes());
}

From source file:com.cloudhopper.smpp.transcoder.PduDecoderTest.java

License:Apache License

@Test
public void decodeSubmitSmRespWithNoMessageId() throws Exception {
    ByteBuf buffer = BufferHelper.createBuffer("0000001080000004000000000a342ee1");

    SubmitSmResp pdu0 = (SubmitSmResp) transcoder.decode(buffer);

    Assert.assertEquals(16, pdu0.getCommandLength());
    Assert.assertEquals(0x80000004, pdu0.getCommandId());
    Assert.assertEquals(0, pdu0.getCommandStatus());
    Assert.assertEquals(171192033, pdu0.getSequenceNumber());
    Assert.assertEquals(true, pdu0.isResponse());
    Assert.assertEquals(null, pdu0.getMessageId());

    Assert.assertEquals(0, buffer.readableBytes());
}

From source file:com.cloudhopper.smpp.transcoder.PduDecoderTest.java

License:Apache License

@Test
public void decodeSubmitSmRespWithEmptyMessageId() throws Exception {
    ByteBuf buffer = BufferHelper.createBuffer("0000001180000004000000000a342ee100");

    SubmitSmResp pdu0 = (SubmitSmResp) transcoder.decode(buffer);

    Assert.assertEquals(17, pdu0.getCommandLength());
    Assert.assertEquals(0x80000004, pdu0.getCommandId());
    Assert.assertEquals(0, pdu0.getCommandStatus());
    Assert.assertEquals(171192033, pdu0.getSequenceNumber());
    Assert.assertEquals(true, pdu0.isResponse());
    Assert.assertEquals("", pdu0.getMessageId());

    Assert.assertEquals(0, buffer.readableBytes());
}

From source file:com.cloudhopper.smpp.transcoder.PduDecoderTest.java

License:Apache License

@Test
public void decodeSubmitSmRespWithNoNullByteForMessageId() throws Exception {
    ByteBuf buffer = BufferHelper.createBuffer("0000001180000004000000000a342ee139");

    SubmitSmResp pdu0 = null;//from   w  w w .  j av a2s.  c  o m
    try {
        pdu0 = (SubmitSmResp) transcoder.decode(buffer);
        Assert.fail();
    } catch (TerminatingNullByteNotFoundException e) {
        // correct behavior (should still be able to get partial PDU
        pdu0 = (SubmitSmResp) e.getPartialPdu();
    }

    Assert.assertEquals(17, pdu0.getCommandLength());
    Assert.assertEquals(SmppConstants.CMD_ID_SUBMIT_SM_RESP, pdu0.getCommandId());
    Assert.assertEquals(0, pdu0.getCommandStatus());
    Assert.assertEquals(171192033, pdu0.getSequenceNumber());
    Assert.assertEquals(true, pdu0.isResponse());
    Assert.assertEquals(null, pdu0.getMessageId());
    Assert.assertEquals(0, buffer.readableBytes());
}

From source file:com.cloudhopper.smpp.transcoder.PduDecoderTest.java

License:Apache License

@Test
public void decodeDeliverSmResp() throws Exception {
    ByteBuf buffer = BufferHelper.createBuffer("0000001c800000050000000000116ac7393432353834333135393400");

    DeliverSmResp pdu0 = (DeliverSmResp) transcoder.decode(buffer);

    Assert.assertEquals(28, pdu0.getCommandLength());
    Assert.assertEquals(SmppConstants.CMD_ID_DELIVER_SM_RESP, pdu0.getCommandId());
    Assert.assertEquals(0, pdu0.getCommandStatus());
    Assert.assertEquals(1141447, pdu0.getSequenceNumber());
    Assert.assertEquals(true, pdu0.isResponse());
    Assert.assertEquals("94258431594", pdu0.getMessageId());
    Assert.assertEquals(0, buffer.readableBytes());
}