消息解析接口
This commit is contained in:
parent
ea4cfdd042
commit
2615bbf3d6
@ -1,9 +1,11 @@
|
||||
package club.joylink.xiannccda.ats.message;
|
||||
|
||||
public class MessageData {
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public abstract class MessageData {
|
||||
|
||||
/**
|
||||
* 消息的长度: 时间戳(Time)长度+ 版本号(Version)长度+消息ID(message _id)长度(2字节)+ 消息内容(content)长度。
|
||||
* 2字节,消息的长度: 时间戳(Time)长度+ 版本号(Version)长度+消息ID(message _id)长度(2字节)+ 消息内容(content)长度。
|
||||
*/
|
||||
int length;
|
||||
/**
|
||||
@ -11,8 +13,33 @@ public class MessageData {
|
||||
*/
|
||||
long time;
|
||||
/**
|
||||
* 用来区分协议的版本,本版指定为01H
|
||||
* 2字节,用来区分协议的版本,本版指定为01H
|
||||
*/
|
||||
int version;
|
||||
/**
|
||||
* 2字节,消息id
|
||||
*/
|
||||
MessageId msgId;
|
||||
|
||||
public void decode(ByteBuf buf) throws Exception {
|
||||
final int headerBytes = 10;
|
||||
int readableBytes = buf.readableBytes();
|
||||
if (readableBytes >= headerBytes) {
|
||||
this.length = buf.readUnsignedShort();
|
||||
this.time = buf.readUnsignedInt();
|
||||
this.version = buf.readUnsignedShort();
|
||||
this.msgId = MessageId.of(buf.readShort());
|
||||
} else {
|
||||
throw new Exception(
|
||||
String.format("OCC消息可读字节数小于%s:readableBytes=%s", headerBytes, readableBytes));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析,公共消息的解析已经处理过,只需继续往后读取并解析
|
||||
*
|
||||
* @param buf
|
||||
* @throws Exception
|
||||
*/
|
||||
public abstract void decode2(ByteBuf buf) throws Exception;
|
||||
}
|
||||
|
@ -1,7 +1,12 @@
|
||||
package club.joylink.xiannccda.ats.message.line3;
|
||||
|
||||
import club.joylink.xiannccda.ats.message.MessageData;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class HeartBeatMsg extends MessageData {
|
||||
|
||||
@Override
|
||||
public void decode2(ByteBuf buf) throws Exception {
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user