update all wireEncode & add packet test: CPacket

This commit is contained in:
free will committed 2021-04-07 16:37:05 +08:00
1 parent 424d182d60
commit 2bf431af9c
33 files changed
+335 -317

No files matched your search

+16 -3
View File
@@ -16,7 +16,10 @@ import encoding.*;
// @Description:
// 1. 包格式定义如下:
// CPacket = 5 TLV-LENGTH
// { CommonIdentifier } => 标识区
// { => 标识区
// SrcIdentifier => 源标识
// DstIdentifier => 目的标识
// }
// { Signature } => 签名区
// { => 只读区
// <Payload>
@@ -101,6 +104,14 @@ public class CPacket implements InteractWithField, IEncodingAble {
}
}
/**
* 获取payload中的value
* @return
*/
public byte[] getValue(){
return this.payload.getValue();
}
/**
* 将 CPacket 的各项属性填充到 MINPacket 中定义的对应分区当中
*
@@ -117,6 +128,7 @@ public class CPacket implements InteractWithField, IEncodingAble {
this.minPacket.mutableField.mutableDangerousField.clearBlocks();
Block block = new SelfEncodingBase().selfWireEncode(this.ttl);
if (block == null) {
System.out.println("err 1");
return false;
}
this.minPacket.mutableField.mutableDangerousField.addBlock(block);
@@ -126,6 +138,7 @@ public class CPacket implements InteractWithField, IEncodingAble {
this.minPacket.readOnlyField.clearBlocks();
block = new SelfEncodingBase().selfWireEncode(this.payload);
if (block == null) {
System.out.println("err 2");
return false;
}
this.minPacket.readOnlyField.addBlock(block);
@@ -162,7 +175,7 @@ public class CPacket implements InteractWithField, IEncodingAble {
if (payloadBlock == null) {
return false;
}
if (this.payload.wireDecode(payloadBlock)) {
if (!this.payload.wireDecode(payloadBlock)) {
return false;
}
@@ -171,7 +184,7 @@ public class CPacket implements InteractWithField, IEncodingAble {
if (ttlBlock == null) {
return false;
}
if (this.ttl.wireDecode(ttlBlock)) {
if (!this.ttl.wireDecode(ttlBlock)) {
return false;
}