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 decodeDeliverSmRespWithEmptyMessageId() throws Exception {
    ByteBuf buffer = BufferHelper.createBuffer("00000011800000050000000000116ac700");

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

    Assert.assertEquals(17, 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("", pdu0.getMessageId());
    Assert.assertEquals(0, buffer.readableBytes());
}

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

License:Apache License

@Test
public void decodeDeliverSmRespWithNoMessageId() throws Exception {
    ByteBuf buffer = BufferHelper.createBuffer("00000010800000050000000000116ac7");

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

    Assert.assertEquals(16, 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(null, pdu0.getMessageId());
    Assert.assertEquals(0, buffer.readableBytes());
}

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

License:Apache License

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

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

    Assert.assertEquals(28, pdu0.getCommandLength());
    Assert.assertEquals(SmppConstants.CMD_ID_DATA_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());
}

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

License:Apache License

@Test
public void decodeDataSmRespWithEmptyMessageId() throws Exception {
    ByteBuf buffer = BufferHelper.createBuffer("00000011800001030000000000116ac700");

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

    Assert.assertEquals(17, pdu0.getCommandLength());
    Assert.assertEquals(SmppConstants.CMD_ID_DATA_SM_RESP, pdu0.getCommandId());
    Assert.assertEquals(0, pdu0.getCommandStatus());
    Assert.assertEquals(1141447, 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 decodeDataSmRespWithNoMessageId() throws Exception {
    ByteBuf buffer = BufferHelper.createBuffer("00000010800001030000000000116ac7");

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

    Assert.assertEquals(16, pdu0.getCommandLength());
    Assert.assertEquals(SmppConstants.CMD_ID_DATA_SM_RESP, pdu0.getCommandId());
    Assert.assertEquals(0, pdu0.getCommandStatus());
    Assert.assertEquals(1141447, 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 decodeBindTransceiverResp() throws Exception {
    ByteBuf buffer = BufferHelper
            .createBuffer("0000001f800000090000000000039951536d73632053696d756c61746f7200");

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

    Assert.assertEquals(31, pdu0.getCommandLength());
    Assert.assertEquals(SmppConstants.CMD_ID_BIND_TRANSCEIVER_RESP, pdu0.getCommandId());
    Assert.assertEquals(0, pdu0.getCommandStatus());
    Assert.assertEquals(235857, pdu0.getSequenceNumber());
    Assert.assertEquals(true, pdu0.isResponse());
    Assert.assertEquals("Smsc Simulator", pdu0.getSystemId());

    // interesting -- this example has optional parameters it happened to skip...
    Assert.assertEquals(0, buffer.readableBytes());
}

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

License:Apache License

@Test
public void decodeBindTransceiverRespFailedButWithSystemId() throws Exception {
    // this specific PDU actually failed with legacy smpp library
    ByteBuf buffer = BufferHelper.createBuffer("00000015800000090000000e00004db3534d534300");

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

    Assert.assertEquals(21, pdu0.getCommandLength());
    Assert.assertEquals(SmppConstants.CMD_ID_BIND_TRANSCEIVER_RESP, pdu0.getCommandId());
    Assert.assertEquals(0x0000000e, pdu0.getCommandStatus());
    Assert.assertEquals(19891, pdu0.getSequenceNumber());
    Assert.assertEquals(true, pdu0.isResponse());
    Assert.assertEquals("SMSC", pdu0.getSystemId());

    // interesting -- this example has optional parameters it happened to skip...
    Assert.assertEquals(0, buffer.readableBytes());
}

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

License:Apache License

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

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

    Assert.assertEquals(29, pdu0.getCommandLength());
    Assert.assertEquals(SmppConstants.CMD_ID_BIND_TRANSCEIVER_RESP, pdu0.getCommandId());
    Assert.assertEquals(0, pdu0.getCommandStatus());
    Assert.assertEquals(235843, pdu0.getSequenceNumber());
    Assert.assertEquals(true, pdu0.isResponse());
    Assert.assertEquals("Smsc GW", pdu0.getSystemId());
    Assert.assertEquals(1, pdu0.getOptionalParameters().size());
    Assert.assertEquals(true, pdu0.hasOptionalParameter(SmppConstants.TAG_SC_INTERFACE_VERSION));
    Assert.assertEquals(SmppConstants.TAG_SC_INTERFACE_VERSION, pdu0.getOptionalParameters().get(0).getTag());
    Assert.assertEquals(1, pdu0.getOptionalParameters().get(0).getLength());
    Assert.assertArrayEquals(new byte[] { (byte) 0x34 }, pdu0.getOptionalParameters().get(0).getValue());

    // interesting -- this example has optional parameters it happened to skip...
    Assert.assertEquals(0, buffer.readableBytes());
}

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

License:Apache License

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

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

    Assert.assertEquals(29, pdu0.getCommandLength());
    Assert.assertEquals(SmppConstants.CMD_ID_BIND_TRANSMITTER_RESP, pdu0.getCommandId());
    Assert.assertEquals(0, pdu0.getCommandStatus());
    Assert.assertEquals(235871, pdu0.getSequenceNumber());
    Assert.assertEquals(true, pdu0.isResponse());
    Assert.assertEquals("TWITTER", pdu0.getSystemId());
    Assert.assertEquals(1, pdu0.getOptionalParameters().size());
    Assert.assertEquals(true, pdu0.hasOptionalParameter(SmppConstants.TAG_SC_INTERFACE_VERSION));
    Assert.assertEquals(SmppConstants.TAG_SC_INTERFACE_VERSION, pdu0.getOptionalParameters().get(0).getTag());
    Assert.assertEquals(1, pdu0.getOptionalParameters().get(0).getLength());
    Assert.assertArrayEquals(new byte[] { (byte) 0x34 }, pdu0.getOptionalParameters().get(0).getValue());

    // interesting -- this example has optional parameters it happened to skip...
    Assert.assertEquals(0, buffer.readableBytes());
}

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

License:Apache License

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

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

    Assert.assertEquals(29, pdu0.getCommandLength());
    Assert.assertEquals(SmppConstants.CMD_ID_BIND_RECEIVER_RESP, pdu0.getCommandId());
    Assert.assertEquals(0, pdu0.getCommandStatus());
    Assert.assertEquals(235874, pdu0.getSequenceNumber());
    Assert.assertEquals(true, pdu0.isResponse());
    Assert.assertEquals("twitter", pdu0.getSystemId());
    Assert.assertEquals(1, pdu0.getOptionalParameters().size());
    Assert.assertEquals(true, pdu0.hasOptionalParameter(SmppConstants.TAG_SC_INTERFACE_VERSION));
    Tlv tlv0 = pdu0.getOptionalParameter(SmppConstants.TAG_SC_INTERFACE_VERSION);
    Assert.assertEquals(SmppConstants.TAG_SC_INTERFACE_VERSION, tlv0.getTag());
    Assert.assertEquals(1, tlv0.getLength());
    Assert.assertArrayEquals(new byte[] { (byte) 0x34 }, tlv0.getValue());

    // interesting -- this example has optional parameters it happened to skip...
    Assert.assertEquals(0, buffer.readableBytes());
}