mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
add error handle; SizeT
This commit is contained in:
1 parent
de55943194
commit
d46b3c15cd
4 files changed
+76
-199
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user