add error handle; SizeT

This commit is contained in:
free will committed 2021-03-17 10:52:01 +08:00
1 parent de55943194
commit d46b3c15cd
4 files changed
+76 -199

No files matched your search

+46 -12
View File
@@ -43,9 +43,15 @@ public class Encoder {
this.isInitial=true;
this.isEstimator=false;
this.totalReserve=totalReserve;
this.buffer=new byte[totalReserve.getVlIntValue2Int()]; //todo: 特殊情况下,可能越界。
this.left=totalReserve.subtract(reserveFromBack)-1;//todo: 特殊情况下,可能越界。
this.right=totalReserve.subtract(reserveFromBack);//todo: 特殊情况下,可能越界。
int len=0;
try {
len=totalReserve.getVlIntValue2Int();
} catch (VlIntException e) {
throw new Error("Encoder.encoderReset: "+e.getMessage());
}
this.buffer=new byte[len]; //todo: 特殊情况下,可能越界。
this.left= (int) (totalReserve.subtract(reserveFromBack)-1);//todo: 特殊情况下,可能越界。
this.right= (int) totalReserve.subtract(reserveFromBack);//todo: 特殊情况下,可能越界。
return true;
}
@@ -172,12 +178,24 @@ public class Encoder {
if(check(size)&&(size.compareTo(array.length)<=0)){
if(this.isEstimator){
this.left-=array.length;
return size.getVlIntValue2Int();
try {
return size.getVlIntValue2Int();
} catch (VlIntException e) {
throw new Error("Encoder.prependByteArray: "+e.getMessage());
}
}else{
System.arraycopy(array,0,this.buffer,
this.left-size.getVlIntValue2Int()+1,size.getVlIntValue2Int());
try {
System.arraycopy(array,0,this.buffer,
this.left-size.getVlIntValue2Int()+1,size.getVlIntValue2Int());
} catch (VlIntException e) {
throw new Error("Encoder.prependByteArray: "+e.getMessage());
}
this.left-=array.length;
return size.getVlIntValue2Int();
try {
return size.getVlIntValue2Int();
} catch (VlIntException e) {
throw new Error("Encoder.prependByteArray: "+e.getMessage());
}
}
}
return 0;
@@ -192,12 +210,24 @@ public class Encoder {
if(check(size)&&(size.compareTo(array.length)<=0)){
if(this.isEstimator){
this.right+=array.length;
return size.getVlIntValue2Int();
try {
return size.getVlIntValue2Int();
} catch (VlIntException e) {
throw new Error("Encoder.appendByteArray: "+e.getMessage());
}
}else{
System.arraycopy(array,0,this.buffer,
this.right,size.getVlIntValue2Int());
try {
System.arraycopy(array,0,this.buffer,
this.right,size.getVlIntValue2Int());
} catch (VlIntException e) {
throw new Error("Encoder.appendByteArray: "+e.getMessage());
}
this.right+=array.length;
return size.getVlIntValue2Int();
try {
return size.getVlIntValue2Int();
} catch (VlIntException e) {
throw new Error("Encoder.appendByteArray: "+e.getMessage());
}
}
}
return 0;
@@ -246,7 +276,11 @@ public class Encoder {
*/
public int appendByteArrayBlock(VlInt tlvType,byte[] array,SizeT size){
int totalLength=this.appendByteArray(array,size);
totalLength+=this.appendVarNumber(new VlInt(size.getVlIntValue2Long()));
try {
totalLength+=this.appendVarNumber(new VlInt(size.getVlIntValue2Long()));
} catch (VlIntException e) {
throw new Error("Encoder.appendByteArrayBlock: "+e.getMessage());
}
totalLength+=this.appendVarNumber(tlvType);
return totalLength;
}