List of usage examples for io.netty.buffer ByteBuf readableBytes
public abstract int readableBytes();
From source file:com.cloudhopper.smpp.transcoder.PduDecoderTest.java
License:Apache License
@Test public void decodeBindTransceiver() throws Exception { ByteBuf buffer = BufferHelper .createBuffer("00000023000000090000000000039951414c4c5f545700414c4c5f5457000034010200"); BindTransceiver pdu0 = (BindTransceiver) transcoder.decode(buffer); Assert.assertEquals(35, pdu0.getCommandLength()); Assert.assertEquals(SmppConstants.CMD_ID_BIND_TRANSCEIVER, pdu0.getCommandId()); Assert.assertEquals(0, pdu0.getCommandStatus()); Assert.assertEquals(235857, pdu0.getSequenceNumber()); Assert.assertEquals(true, pdu0.isRequest()); Assert.assertEquals("ALL_TW", pdu0.getSystemId()); Assert.assertEquals("ALL_TW", pdu0.getPassword()); Assert.assertEquals("", pdu0.getSystemType()); Assert.assertEquals((byte) 0x34, pdu0.getInterfaceVersion()); Assert.assertEquals((byte) 0x01, pdu0.getAddressRange().getTon()); Assert.assertEquals((byte) 0x02, pdu0.getAddressRange().getNpi()); Assert.assertEquals("", pdu0.getAddressRange().getAddress()); // 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 decodeBindTransmitter() throws Exception { ByteBuf buffer = BufferHelper .createBuffer("0000002500000002000000000003995f747769747465720074776974746572000034000000"); BindTransmitter pdu0 = (BindTransmitter) transcoder.decode(buffer); Assert.assertEquals(37, pdu0.getCommandLength()); Assert.assertEquals(SmppConstants.CMD_ID_BIND_TRANSMITTER, pdu0.getCommandId()); Assert.assertEquals(0, pdu0.getCommandStatus()); Assert.assertEquals(235871, pdu0.getSequenceNumber()); Assert.assertEquals(true, pdu0.isRequest()); Assert.assertEquals("twitter", pdu0.getSystemId()); Assert.assertEquals("twitter", pdu0.getPassword()); Assert.assertEquals("", pdu0.getSystemType()); Assert.assertEquals((byte) 0x34, pdu0.getInterfaceVersion()); Assert.assertEquals((byte) 0x00, pdu0.getAddressRange().getTon()); Assert.assertEquals((byte) 0x00, pdu0.getAddressRange().getNpi()); Assert.assertEquals("", pdu0.getAddressRange().getAddress()); // 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 decodeBindReceiver() throws Exception { ByteBuf buffer = BufferHelper .createBuffer("00000025000000010000000000039961747769747465720074776974746572000034000000"); BindReceiver pdu0 = (BindReceiver) transcoder.decode(buffer); Assert.assertEquals(37, pdu0.getCommandLength()); Assert.assertEquals(SmppConstants.CMD_ID_BIND_RECEIVER, pdu0.getCommandId()); Assert.assertEquals(0, pdu0.getCommandStatus()); Assert.assertEquals(235873, pdu0.getSequenceNumber()); Assert.assertEquals(true, pdu0.isRequest()); Assert.assertEquals("twitter", pdu0.getSystemId()); Assert.assertEquals("twitter", pdu0.getPassword()); Assert.assertEquals("", pdu0.getSystemType()); Assert.assertEquals((byte) 0x34, pdu0.getInterfaceVersion()); Assert.assertEquals((byte) 0x00, pdu0.getAddressRange().getTon()); Assert.assertEquals((byte) 0x00, pdu0.getAddressRange().getNpi()); Assert.assertEquals("", pdu0.getAddressRange().getAddress()); // 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 decodeDeliverSm() throws Exception { ByteBuf buffer = BufferHelper.createBuffer( "000000400000000500000000000000030002013837363534333231000409343034303400000000000000000000084024232125262F3A000E0001010006000101"); DeliverSm pdu0 = (DeliverSm) transcoder.decode(buffer); Assert.assertEquals(64, pdu0.getCommandLength()); Assert.assertEquals(SmppConstants.CMD_ID_DELIVER_SM, pdu0.getCommandId()); Assert.assertEquals(0, pdu0.getCommandStatus()); Assert.assertEquals(3, pdu0.getSequenceNumber()); Assert.assertEquals(true, pdu0.isRequest()); Assert.assertEquals("", pdu0.getServiceType()); Assert.assertEquals(0x02, pdu0.getSourceAddress().getTon()); Assert.assertEquals(0x01, pdu0.getSourceAddress().getNpi()); Assert.assertEquals("87654321", pdu0.getSourceAddress().getAddress()); Assert.assertEquals(0x04, pdu0.getDestAddress().getTon()); Assert.assertEquals(0x09, pdu0.getDestAddress().getNpi()); Assert.assertEquals("40404", pdu0.getDestAddress().getAddress()); Assert.assertEquals(0x00, pdu0.getEsmClass()); Assert.assertEquals(0x00, pdu0.getProtocolId()); Assert.assertEquals(0x00, pdu0.getPriority()); Assert.assertEquals("", pdu0.getScheduleDeliveryTime()); Assert.assertEquals("", pdu0.getValidityPeriod()); Assert.assertEquals(0x00, pdu0.getRegisteredDelivery()); Assert.assertEquals(0x00, pdu0.getReplaceIfPresent()); Assert.assertEquals(0x00, pdu0.getDataCoding()); Assert.assertEquals(0x00, pdu0.getDefaultMsgId()); Assert.assertEquals(8, pdu0.getShortMessage().length); Assert.assertArrayEquals(HexUtil.toByteArray("4024232125262f3a"), pdu0.getShortMessage()); Assert.assertEquals(2, pdu0.getOptionalParameters().size()); Tlv tlv0 = pdu0.getOptionalParameter(SmppConstants.TAG_SOURCE_NETWORK_TYPE); Assert.assertEquals(0x01, tlv0.getValueAsByte()); Tlv tlv1 = pdu0.getOptionalParameter(SmppConstants.TAG_DEST_NETWORK_TYPE); Assert.assertEquals(0x01, tlv1.getValueAsByte()); // 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 decodeDeliverSmAsDeliveryReceipt() throws Exception { ByteBuf buffer = BufferHelper.createBuffer( "000000BA00000005000000000000000200010134343935313336313932300001013430343034000400000000000000006E69643A30303539313133393738207375623A30303120646C7672643A303031207375626D697420646174653A3130303231303137333020646F6E6520646174653A3130303231303137333120737461743A44454C49565244206572723A30303020746578743A4024232125262F3A000E0001010006000101001E000833383630316661000427000102"); DeliverSm pdu0 = (DeliverSm) transcoder.decode(buffer); Assert.assertEquals(186, pdu0.getCommandLength()); Assert.assertEquals(SmppConstants.CMD_ID_DELIVER_SM, pdu0.getCommandId()); Assert.assertEquals(0, pdu0.getCommandStatus()); Assert.assertEquals(2, pdu0.getSequenceNumber()); Assert.assertEquals(true, pdu0.isRequest()); Assert.assertEquals("", pdu0.getServiceType()); Assert.assertEquals(0x01, pdu0.getSourceAddress().getTon()); Assert.assertEquals(0x01, pdu0.getSourceAddress().getNpi()); Assert.assertEquals("44951361920", pdu0.getSourceAddress().getAddress()); Assert.assertEquals(0x01, pdu0.getDestAddress().getTon()); Assert.assertEquals(0x01, pdu0.getDestAddress().getNpi()); Assert.assertEquals("40404", pdu0.getDestAddress().getAddress()); Assert.assertEquals(0x04, pdu0.getEsmClass()); Assert.assertEquals(0x00, pdu0.getProtocolId()); Assert.assertEquals(0x00, pdu0.getPriority()); Assert.assertEquals("", pdu0.getScheduleDeliveryTime()); Assert.assertEquals("", pdu0.getValidityPeriod()); Assert.assertEquals(0x00, pdu0.getRegisteredDelivery()); Assert.assertEquals(0x00, pdu0.getReplaceIfPresent()); Assert.assertEquals(0x00, pdu0.getDataCoding()); Assert.assertEquals(0x00, pdu0.getDefaultMsgId()); Assert.assertEquals(110, pdu0.getShortMessage().length); Assert.assertArrayEquals(HexUtil.toByteArray( "69643a30303539313133393738207375623a30303120646c7672643a303031207375626d697420646174653a3130303231303137333020646f6e6520646174653a3130303231303137333120737461743a44454c49565244206572723a30303020746578743a4024232125262f3a"), pdu0.getShortMessage());/*w w w . j a v a 2 s . c o m*/ Assert.assertEquals(4, pdu0.getOptionalParameters().size()); Tlv tlv0 = pdu0.getOptionalParameter(SmppConstants.TAG_SOURCE_NETWORK_TYPE); Assert.assertEquals(0x01, tlv0.getValueAsByte()); Tlv tlv1 = pdu0.getOptionalParameter(SmppConstants.TAG_DEST_NETWORK_TYPE); Assert.assertEquals(0x01, tlv1.getValueAsByte()); Tlv tlv2 = pdu0.getOptionalParameter(SmppConstants.TAG_RECEIPTED_MSG_ID); Assert.assertEquals("38601fa", tlv2.getValueAsString()); Tlv tlv3 = pdu0.getOptionalParameter(SmppConstants.TAG_MSG_STATE); Assert.assertEquals(SmppConstants.STATE_DELIVERED, tlv3.getValueAsByte()); // 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/*from w w w . j a v a 2 s . c o m*/ public void decodeDeliverSmNetforsDeliveryReceiptTriggeredErrorInLegacySmppLibrary() throws Exception { // interesting -- the optional parameter in this TLV is actually incorrect // it has a length of 0x41, but only 5 bytes were actually included // notified vendor this was a mistake, but perhaps we should try to make // this implementation work somehow? ByteBuf buffer = BufferHelper.createBuffer("000000a40000000500000000000000050001013233343830333337363831353100050056414e534f000400000000040000006369643a30303030303033303035207375623a30303120646c7672643a303031207375626d697420646174653a3130303131383134333120646f6e6520646174653a3130303131383134333120737461743a44454c49565244206572723a3030302074650427000102001e00413330303500"); DeliverSm pdu0 = (DeliverSm)PduDecoder.decode(buffer); Assert.assertEquals(164, pdu0.getCommandLength()); Assert.assertEquals(SmppConstants.CMD_ID_DELIVER_SM, pdu0.getCommandId()); Assert.assertEquals(0, pdu0.getCommandStatus()); Assert.assertEquals(5, pdu0.getSequenceNumber()); Assert.assertEquals(true, pdu0.isRequest()); Assert.assertEquals("", pdu0.getServiceType()); Assert.assertEquals(0x01, pdu0.getSourceAddress().getTon()); Assert.assertEquals(0x01, pdu0.getSourceAddress().getNpi()); Assert.assertEquals("2348033768151", pdu0.getSourceAddress()); Assert.assertEquals(0x05, pdu0.getDestAddress().getTon()); Assert.assertEquals(0x00, pdu0.getDestAddress().getNpi()); Assert.assertEquals("VANSO", pdu0.getDestinationAddress()); Assert.assertEquals(0x04, pdu0.getEsmClass()); Assert.assertEquals(0x00, pdu0.getProtocolId()); Assert.assertEquals(0x00, pdu0.getPriority()); Assert.assertEquals("", pdu0.getScheduleDeliveryTime()); Assert.assertEquals("", pdu0.getValidityPeriod()); Assert.assertEquals(0x04, pdu0.getRegisteredDelivery()); Assert.assertEquals(0x00, pdu0.getReplaceIfPresent()); Assert.assertEquals(0x00, pdu0.getDataCoding()); Assert.assertEquals(0x00, pdu0.getDefaultMsgId()); Assert.assertEquals(99, pdu0.getShortMessage().length); Assert.assertArrayEquals(StringUtil.fromHexString("69643a30303030303033303035207375623a30303120646c7672643a303031207375626d697420646174653a3130303131383134333120646f6e6520646174653a3130303131383134333120737461743a44454c49565244206572723a303030207465"), pdu0.getShortMessage()); Assert.assertEquals(4, pdu0.getOptionalParameters().size()); Tlv tlv0 = pdu0.getOptionalParameter(SmppConstants.TAG_SOURCE_NETWORK_TYPE); Assert.assertEquals(0x01, tlv0.getValueAsByte()); Tlv tlv1 = pdu0.getOptionalParameter(SmppConstants.TAG_DEST_NETWORK_TYPE); Assert.assertEquals(0x01, tlv1.getValueAsByte()); Tlv tlv2 = pdu0.getOptionalParameter(SmppConstants.TAG_RECEIPTED_MSG_ID); Assert.assertEquals("38601fa", tlv2.getValueAsString()); Tlv tlv3 = pdu0.getOptionalParameter(SmppConstants.TAG_MSG_STATE); Assert.assertEquals(SmppConstants.STATE_DELIVERED, tlv3.getValueAsByte()); // interesting -- this example has optional parameters it happened to skip... Assert.assertEquals(0, buffer.readableBytes()); } */ @Test public void decodeSubmitSm() throws Exception { ByteBuf buffer = BufferHelper.createBuffer( "00000039000000040000000000004FE80001013430343034000101343439353133363139323000000000000001000000084024232125262F3A"); SubmitSm pdu0 = (SubmitSm) transcoder.decode(buffer); Assert.assertEquals(57, pdu0.getCommandLength()); Assert.assertEquals(SmppConstants.CMD_ID_SUBMIT_SM, pdu0.getCommandId()); Assert.assertEquals(0, pdu0.getCommandStatus()); Assert.assertEquals(20456, pdu0.getSequenceNumber()); Assert.assertEquals(true, pdu0.isRequest()); Assert.assertEquals("", pdu0.getServiceType()); Assert.assertEquals(0x01, pdu0.getSourceAddress().getTon()); Assert.assertEquals(0x01, pdu0.getSourceAddress().getNpi()); Assert.assertEquals("40404", pdu0.getSourceAddress().getAddress()); Assert.assertEquals(0x01, pdu0.getDestAddress().getTon()); Assert.assertEquals(0x01, pdu0.getDestAddress().getNpi()); Assert.assertEquals("44951361920", pdu0.getDestAddress().getAddress()); Assert.assertEquals(0x00, pdu0.getEsmClass()); Assert.assertEquals(0x00, pdu0.getProtocolId()); Assert.assertEquals(0x00, pdu0.getPriority()); Assert.assertEquals("", pdu0.getScheduleDeliveryTime()); Assert.assertEquals("", pdu0.getValidityPeriod()); Assert.assertEquals(0x01, pdu0.getRegisteredDelivery()); Assert.assertEquals(0x00, pdu0.getReplaceIfPresent()); Assert.assertEquals(0x00, pdu0.getDataCoding()); Assert.assertEquals(0x00, pdu0.getDefaultMsgId()); Assert.assertEquals(8, pdu0.getShortMessage().length); Assert.assertArrayEquals(HexUtil.toByteArray("4024232125262f3a"), pdu0.getShortMessage()); Assert.assertEquals(null, pdu0.getOptionalParameters()); // 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 decodeUnbind() throws Exception { ByteBuf buffer = BufferHelper.createBuffer("00000010000000060000000000000001"); Unbind pdu0 = (Unbind) transcoder.decode(buffer); Assert.assertEquals(16, pdu0.getCommandLength()); Assert.assertEquals(SmppConstants.CMD_ID_UNBIND, pdu0.getCommandId()); Assert.assertEquals(0, pdu0.getCommandStatus()); Assert.assertEquals(1, 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 decodeUnbindResp() throws Exception { ByteBuf buffer = BufferHelper.createBuffer("00000010800000060000000000000001"); UnbindResp pdu0 = (UnbindResp) transcoder.decode(buffer); Assert.assertEquals(16, pdu0.getCommandLength()); Assert.assertEquals(SmppConstants.CMD_ID_UNBIND_RESP, pdu0.getCommandId()); Assert.assertEquals(0, pdu0.getCommandStatus()); Assert.assertEquals(1, 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 decodeGenericNak() throws Exception { ByteBuf buffer = BufferHelper.createBuffer("00000010800000000000000100082a77"); GenericNack pdu0 = (GenericNack) transcoder.decode(buffer); logger.debug("{}", pdu0); Assert.assertEquals(16, pdu0.getCommandLength()); Assert.assertEquals(SmppConstants.CMD_ID_GENERIC_NACK, pdu0.getCommandId()); Assert.assertEquals(SmppConstants.STATUS_INVMSGLEN, pdu0.getCommandStatus()); Assert.assertEquals(535159, 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 decodeDeliverSmWithOptionalMessagePayload() throws Exception { ByteBuf buffer = BufferHelper.createBuffer( "000000640000000500000000000547EB0002013434393531333631393200040934303430340000000000000000000000000E000101000600010104240026404D616964656E6D616E363634207761732069742073617070793F2026526F6D616E7469633F"); DeliverSm pdu0 = (DeliverSm) transcoder.decode(buffer); Assert.assertEquals(100, pdu0.getCommandLength()); Assert.assertEquals(SmppConstants.CMD_ID_DELIVER_SM, pdu0.getCommandId()); Assert.assertEquals(0, pdu0.getCommandStatus()); Assert.assertEquals(346091, pdu0.getSequenceNumber()); Assert.assertEquals(true, pdu0.isRequest()); Assert.assertEquals("", pdu0.getServiceType()); Assert.assertEquals(0x02, pdu0.getSourceAddress().getTon()); Assert.assertEquals(0x01, pdu0.getSourceAddress().getNpi()); Assert.assertEquals("4495136192", pdu0.getSourceAddress().getAddress()); Assert.assertEquals(0x04, pdu0.getDestAddress().getTon()); Assert.assertEquals(0x09, pdu0.getDestAddress().getNpi()); Assert.assertEquals("40404", pdu0.getDestAddress().getAddress()); Assert.assertEquals(0x00, pdu0.getEsmClass()); Assert.assertEquals(0x00, pdu0.getProtocolId()); Assert.assertEquals(0x00, pdu0.getPriority()); Assert.assertEquals("", pdu0.getScheduleDeliveryTime()); Assert.assertEquals("", pdu0.getValidityPeriod()); Assert.assertEquals(0x00, pdu0.getRegisteredDelivery()); Assert.assertEquals(0x00, pdu0.getReplaceIfPresent()); Assert.assertEquals(0x00, pdu0.getDataCoding()); Assert.assertEquals(0x00, pdu0.getDefaultMsgId()); Assert.assertEquals(0, pdu0.getShortMessageLength()); Assert.assertArrayEquals(HexUtil.toByteArray(""), pdu0.getShortMessage()); Assert.assertEquals(3, pdu0.getOptionalParameters().size()); Tlv tlv0 = pdu0.getOptionalParameter(SmppConstants.TAG_SOURCE_NETWORK_TYPE); Assert.assertEquals(0x01, tlv0.getValueAsByte()); Tlv tlv1 = pdu0.getOptionalParameter(SmppConstants.TAG_DEST_NETWORK_TYPE); Assert.assertEquals(0x01, tlv1.getValueAsByte()); Tlv tlv2 = pdu0.getOptionalParameter(SmppConstants.TAG_MESSAGE_PAYLOAD); Assert.assertArrayEquals(/*from w w w .ja v a 2 s .c o m*/ HexUtil.toByteArray("404d616964656e6d616e363634207761732069742073617070793f2026526f6d616e7469633f"), tlv2.getValue()); // interesting -- this example has optional parameters it happened to skip... Assert.assertEquals(0, buffer.readableBytes()); }