Search in sources :

Example 1 with SequenceNumber

use of com.zx.sms.common.util.SequenceNumber in project SMSGate by Lihuanghe.

the class SgipHeaderCodec method decode.

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> list) throws Exception {
    // 此时已处理过粘包和断包了,bytebuf里是完整的一帧
    Message message = new DefaultMessage();
    Header header = new DefaultHeader();
    header.setPacketLength(bytebuf.readUnsignedInt());
    header.setCommandId(bytebuf.readInt());
    byte[] seqbytes = new byte[SgipHead.SEQUENCENUMBER.getLength()];
    bytebuf.readBytes(seqbytes);
    SequenceNumber seq = DefaultSequenceNumberUtil.bytes2SequenceN(seqbytes);
    message.setTimestamp(seq.getTimestamp());
    header.setSequenceId(seq.getSequenceId());
    header.setNodeId(seq.getNodeIds());
    header.setHeadLength(SgipHead.COMMANDID.getHeadLength());
    header.setBodyLength(header.getPacketLength() - header.getHeadLength());
    if (header.getBodyLength() > 0) {
        message.setBodyBuffer(new byte[(int) header.getBodyLength()]);
        assert (header.getBodyLength() == bytebuf.readableBytes());
        bytebuf.readBytes(message.getBodyBuffer());
    } else {
        message.setBodyBuffer(GlobalConstance.emptyBytes);
    }
    message.setHeader(header);
    list.add(message);
}
Also used : DefaultMessage(com.zx.sms.codec.cmpp.msg.DefaultMessage) Message(com.zx.sms.codec.cmpp.msg.Message) DefaultMessage(com.zx.sms.codec.cmpp.msg.DefaultMessage) DefaultHeader(com.zx.sms.codec.cmpp.msg.DefaultHeader) Header(com.zx.sms.codec.cmpp.msg.Header) DefaultHeader(com.zx.sms.codec.cmpp.msg.DefaultHeader) SequenceNumber(com.zx.sms.common.util.SequenceNumber)

Example 2 with SequenceNumber

use of com.zx.sms.common.util.SequenceNumber in project SMSGate by Lihuanghe.

the class TestSGIPcodec method test.

@Test
public void test() throws DecoderException {
    System.out.println(new SmsDcs((byte) 8).getAlphabet());
    System.out.println(new SequenceNumber());
    ByteBuf buffer = Unpooled.wrappedBuffer(Hex.decodeHex("000000a8000000030000000011f333f26ebb10dd31303635353931323530323800000000000000000000000000000000000000000000000000000000000001383631383635373131383633360000000000000000363131313800000000000000000000020000000000000000000000000000090000000000000000000000000000000000000000000000000000000000000000010000000000000004323333610000000000000000".toCharArray()));
    SgipSubmitRequestMessage msg = decode(buffer);
    Assert.assertNotNull(msg);
    System.out.println(msg);
    Assert.assertEquals("106559125028", msg.getSpnumber());
    Assert.assertEquals("233a", msg.getMsgContent());
}
Also used : SgipSubmitRequestMessage(com.zx.sms.codec.sgip12.msg.SgipSubmitRequestMessage) SequenceNumber(com.zx.sms.common.util.SequenceNumber) SmsDcs(org.marre.sms.SmsDcs) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 3 with SequenceNumber

use of com.zx.sms.common.util.SequenceNumber in project SMSGate by Lihuanghe.

the class TestSMGPMsgIdUtil method testSequenceNumber.

@Test
public void testSequenceNumber() throws Exception {
    com.zx.sms.common.util.MsgId msgid = new com.zx.sms.common.util.MsgId();
    SequenceNumber t = new SequenceNumber(msgid);
    System.out.println(msgid);
    System.out.println(t);
    Assert.assertEquals(msgid.toString().substring(0, 10), t.toString().subSequence(10, 20));
}
Also used : SequenceNumber(com.zx.sms.common.util.SequenceNumber) MsgId(com.zx.sms.codec.smgp.msg.MsgId) Test(org.junit.Test)

Aggregations

SequenceNumber (com.zx.sms.common.util.SequenceNumber)3 Test (org.junit.Test)2 DefaultHeader (com.zx.sms.codec.cmpp.msg.DefaultHeader)1 DefaultMessage (com.zx.sms.codec.cmpp.msg.DefaultMessage)1 Header (com.zx.sms.codec.cmpp.msg.Header)1 Message (com.zx.sms.codec.cmpp.msg.Message)1 SgipSubmitRequestMessage (com.zx.sms.codec.sgip12.msg.SgipSubmitRequestMessage)1 MsgId (com.zx.sms.codec.smgp.msg.MsgId)1 ByteBuf (io.netty.buffer.ByteBuf)1 SmsDcs (org.marre.sms.SmsDcs)1