use of com.zx.sms.codec.cmpp.msg.DefaultMessage 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.codec.cmpp.msg.DefaultMessage 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);
}
Aggregations