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

+6 -10
View File
@@ -78,33 +78,30 @@ public class ReadOnlyField implements TlvComponentBase, IEncodingAble {
try {
// 如果只读区没有任何子 TLV,则可以去掉只读区 TLV
if (this.blocks.length() == 0) {
return -1;
return 0;
}
int totalLength = 0;
// 编码TLV-VALUE
// 反向遍历,可以保证解码的时候正向输出
for (int i = this.blocks.length() - 1; i >= 0; i--) {
int tmplen = 0;
tmplen = encoder.prependBlock(this.blocks.getBlock(i));
if (tmplen <= 0) {
int tmplen = encoder.prependBlock(this.blocks.getBlock(i));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
}
// 编码 TLV-LENGTH
int tmplen = 0;
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen <= 0) {
int tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvReadOnlyField));
if (tmplen <= 0) {
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
@@ -130,7 +127,6 @@ public class ReadOnlyField implements TlvComponentBase, IEncodingAble {
}
// 解析子 TLV
if (!block.parseSubElements()) {
return false;
}