fixed some test error: Encoder

This commit is contained in:
free will committed 2021-03-23 17:40:17 +08:00
1 parent 5785f29ec3
commit 3daf0156e0
5 files changed
+97 -48

No files matched your search

+10 -9
View File
@@ -26,7 +26,7 @@ public class Encoder {
this.right=1;
this.isInitial=true;
this.isEstimator=true;
this.totalReserve=new SizeT(Long.MAX_VALUE); //todo: 这里可能越界。
this.totalReserve=new SizeT(Long.MAX_VALUE);
}
/**
@@ -138,8 +138,8 @@ public class Encoder {
public byte[] buildNonNegativeIntegerArr(long uint64){
VlInt vlInt=new VlInt(uint64);
int len=vlInt.getVlIntBytes().length;
if(len==1){
return vlInt.getVlIntBytes();
if(uint64<=255){
return new byte[]{(byte) uint64};
}else {
byte[] res = new byte[len - 1];
System.arraycopy(vlInt.getVlIntBytes(),1,res,0,len-1);
@@ -275,13 +275,14 @@ public class Encoder {
* @return
*/
public int appendByteArrayBlock(VlInt tlvType,byte[] array,SizeT size) throws EncoderException {
int totalLength=this.appendByteArray(array,size);
try {
totalLength+=this.appendVarNumber(new VlInt(size.getVlIntValue2Long()));
} catch (VlIntException e) {
throw new EncoderException("appendByteArrayBlock: "+e.getMessage());
}
int totalLength=0;
// Append TLV-TYPE
totalLength+=this.appendVarNumber(tlvType);
// Append TLV-LENGTH
totalLength+=this.appendVarNumber(new VlInt(size));
// Append TLV-VALUE
totalLength+=this.appendByteArray(array,size);
return totalLength;
}