修复bytehelper & VlInt中的已知bug

This commit is contained in:
ghy committed 2021-03-15 20:46:03 +08:00
1 parent 227d10a391
commit 2ad446ca2c
29 files changed
+315 -80

No files matched your search

+11 -3
View File
@@ -2,6 +2,7 @@ package encoding;
import util.ByteHelper;
import util.ByteHelperException;
/*
* @Author: Wang Feng
@@ -72,13 +73,15 @@ public class TLV {
* @param start
* @return
*/
public static VlInt readVarNumber(byte[] buffer,VlInt start){
public static VlInt readVarNumber(byte[] buffer,VlInt start) throws ByteHelperException {
VlInt length=new VlInt(buffer.length);
if(start.compareTo(length)>=0){
return null;
}
int firstbyte=ByteHelper.uint8ToInt(ByteHelper.getFirstByte(buffer,start));
int firstbyte= 0;
firstbyte = ByteHelper.uint8ToInt(ByteHelper.getFirstByte(buffer,start));
if(firstbyte<241){
return new VlInt(firstbyte);
}else if(firstbyte==241){
@@ -108,7 +111,12 @@ public class TLV {
* @return
*/
public static VlInt readType(byte[] buffer,VlInt start){
VlInt tlvType=readVarNumber(buffer,start);
VlInt tlvType= null;
try {
tlvType = readVarNumber(buffer,start);
} catch (ByteHelperException e) {
e.printStackTrace();
}
if(tlvType==null||tlvType.isEqual(0)||tlvType.compareTo(MaxTlvNum)>0){
return null;