mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
修复bytehelper & VlInt中的已知bug
This commit is contained in:
1 parent
227d10a391
commit
2ad446ca2c
29 files changed
+315
-80
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package encoding;
|
||||
|
||||
import util.ByteHelper;
|
||||
import util.ByteHelperException;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -43,7 +44,12 @@ public class Block {
|
||||
}
|
||||
|
||||
// 读取length
|
||||
VlInt tlvLength=TLV.readVarNumber(buffer,new VlInt(tlvType.size()));
|
||||
VlInt tlvLength= null;
|
||||
try {
|
||||
tlvLength = TLV.readVarNumber(buffer,new VlInt(tlvType.size()));
|
||||
} catch (ByteHelperException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(tlvLength==null){
|
||||
return null;
|
||||
}
|
||||
@@ -197,7 +203,7 @@ public class Block {
|
||||
* 2. 如果TLV的value不为空,且不存在嵌套的子TLV,则会抛出错误
|
||||
* @return
|
||||
*/
|
||||
public boolean parseSubElements(){
|
||||
public boolean parseSubElements() {
|
||||
if((this.value.length==0)||this.elements.length()!=0){
|
||||
return true;
|
||||
}
|
||||
@@ -213,7 +219,12 @@ public class Block {
|
||||
start+=tlvType.size();
|
||||
|
||||
// 读取 TLV-LENGTH
|
||||
VlInt tlvLength=TLV.readVarNumber(this.value,new VlInt(start));
|
||||
VlInt tlvLength= null;
|
||||
try {
|
||||
tlvLength = TLV.readVarNumber(this.value,new VlInt(start));
|
||||
} catch (ByteHelperException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(tlvType==null){
|
||||
this.clearElements();
|
||||
return false;
|
||||
@@ -227,14 +238,19 @@ public class Block {
|
||||
}
|
||||
|
||||
// 创建一个子 TLV Block 并添加到elements当中
|
||||
byte[] subBlockValue=new byte[tlvLength.getVlIntValue2Int()];
|
||||
System.arraycopy(this.value,start,subBlockValue,0,tlvLength.getVlIntValue2Int());
|
||||
Block block=createBlockByTypeLengthBuffer(tlvType,tlvLength,subBlockValue,true);
|
||||
if(block==null){
|
||||
return false;
|
||||
byte[] subBlockValue= new byte[0];
|
||||
try {
|
||||
subBlockValue = new byte[tlvLength.getVlIntValue2Int()];
|
||||
System.arraycopy(this.value,start,subBlockValue,0,tlvLength.getVlIntValue2Int());
|
||||
Block block=createBlockByTypeLengthBuffer(tlvType,tlvLength,subBlockValue,true);
|
||||
if(block==null){
|
||||
return false;
|
||||
}
|
||||
this.addElement(block);
|
||||
start+=tlvLength.getVlIntValue2Int();
|
||||
} catch (VlIntException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.addElement(block);
|
||||
start+=tlvLength.getVlIntValue2Int();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user