Search in sources :

Example 1 with DefaultHeader

use of com.zx.sms.codec.cmpp.msg.DefaultHeader in project SMSGate by Lihuanghe.

the class TestCmppActiveTestRequestMessageCodec method createMsg.

protected CmppActiveTestRequestMessage createMsg() {
    Header header = new DefaultHeader();
    header.setSequenceId(0X761ae);
    CmppActiveTestRequestMessage msg = new CmppActiveTestRequestMessage(header);
    return msg;
}
Also used : DefaultHeader(com.zx.sms.codec.cmpp.msg.DefaultHeader) Header(com.zx.sms.codec.cmpp.msg.Header) CmppActiveTestRequestMessage(com.zx.sms.codec.cmpp.msg.CmppActiveTestRequestMessage) DefaultHeader(com.zx.sms.codec.cmpp.msg.DefaultHeader)

Example 2 with DefaultHeader

use of com.zx.sms.codec.cmpp.msg.DefaultHeader in project SMSGate by Lihuanghe.

the class TestCmpp20DeliverRequestMessageCodec method createTestReq.

private CmppDeliverRequestMessage createTestReq(String content) {
    Header header = new DefaultHeader();
    // 取时间,用来查看编码解码时间
    CmppDeliverRequestMessage msg = new CmppDeliverRequestMessage(header);
    msg.setDestId("13800138000");
    msg.setLinkid("0000");
    // 70个汉字
    msg.setMsgContent(content);
    msg.setMsgId(new MsgId());
    msg.setServiceid("10086");
    msg.setSrcterminalId("13800138000");
    msg.setSrcterminalType((short) 1);
    header.setSequenceId((int) System.nanoTime());
    return msg;
}
Also used : CmppDeliverRequestMessage(com.zx.sms.codec.cmpp.msg.CmppDeliverRequestMessage) DefaultHeader(com.zx.sms.codec.cmpp.msg.DefaultHeader) Header(com.zx.sms.codec.cmpp.msg.Header) DefaultHeader(com.zx.sms.codec.cmpp.msg.DefaultHeader) MsgId(com.zx.sms.common.util.MsgId)

Example 3 with DefaultHeader

use of com.zx.sms.codec.cmpp.msg.DefaultHeader 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 4 with DefaultHeader

use of com.zx.sms.codec.cmpp.msg.DefaultHeader in project SMSGate by Lihuanghe.

the class TestSMPP2CMPPDeliverCodec method createTestReq.

private CmppDeliverRequestMessage createTestReq(String content) {
    Header header = new DefaultHeader();
    // 取时间,用来查看编码解码时间
    CmppDeliverRequestMessage msg = new CmppDeliverRequestMessage(header);
    msg.setDestId("13800138000");
    msg.setLinkid("0000");
    // 70个汉字
    msg.setMsgContent(content);
    msg.setMsgId(new MsgId());
    msg.setServiceid("10086");
    msg.setSrcterminalId("13800138000");
    msg.setSrcterminalType((short) 1);
    header.setSequenceId((int) System.nanoTime());
    return msg;
}
Also used : CmppDeliverRequestMessage(com.zx.sms.codec.cmpp.msg.CmppDeliverRequestMessage) DefaultHeader(com.zx.sms.codec.cmpp.msg.DefaultHeader) Header(com.zx.sms.codec.cmpp.msg.Header) DefaultHeader(com.zx.sms.codec.cmpp.msg.DefaultHeader) MsgId(com.zx.sms.common.util.MsgId)

Example 5 with DefaultHeader

use of com.zx.sms.codec.cmpp.msg.DefaultHeader in project SMSGate by Lihuanghe.

the class CmppHeaderCodec method decode.

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> list) throws Exception {
    // 此时已处理过粘包和断包了,bytebuf里是完整的一帧
    Header header = new DefaultHeader();
    header.setPacketLength(bytebuf.readInt());
    header.setCommandId(bytebuf.readInt());
    header.setSequenceId(bytebuf.readInt());
    header.setHeadLength(CmppHead.COMMANDID.getHeadLength());
    header.setBodyLength(header.getPacketLength() - header.getHeadLength());
    Message message = new DefaultMessage();
    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) DefaultHeader(com.zx.sms.codec.cmpp.msg.DefaultHeader) Header(com.zx.sms.codec.cmpp.msg.Header) Message(com.zx.sms.codec.cmpp.msg.Message) DefaultMessage(com.zx.sms.codec.cmpp.msg.DefaultMessage) DefaultHeader(com.zx.sms.codec.cmpp.msg.DefaultHeader)

Aggregations

DefaultHeader (com.zx.sms.codec.cmpp.msg.DefaultHeader)6 Header (com.zx.sms.codec.cmpp.msg.Header)6 CmppDeliverRequestMessage (com.zx.sms.codec.cmpp.msg.CmppDeliverRequestMessage)3 MsgId (com.zx.sms.common.util.MsgId)3 DefaultMessage (com.zx.sms.codec.cmpp.msg.DefaultMessage)2 Message (com.zx.sms.codec.cmpp.msg.Message)2 CmppActiveTestRequestMessage (com.zx.sms.codec.cmpp.msg.CmppActiveTestRequestMessage)1 SequenceNumber (com.zx.sms.common.util.SequenceNumber)1