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);
}
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());
}
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));
}
Aggregations