finished first component: TTL

This commit is contained in:
free will committed 2021-03-09 11:32:37 +08:00
1 parent 879e09e879
commit 28d7bb2436
9 files changed
+279 -1

No files matched your search

+40
View File
@@ -122,6 +122,46 @@ public class Encoder {
}
/**
* 编码一个非负整数到一个数组当中
* todo: 越界问题
* @param uint64
* @return
*/
public byte[] buildNonNegativeIntegerArr(long uint64){
VlInt vlInt=new VlInt(uint64);
int len=vlInt.getVlIntBytes().length;
if(len==1){
return vlInt.getVlIntBytes();
}else {
byte[] res = new byte[len - 1];
System.arraycopy(vlInt.getVlIntBytes(),1,res,0,len-1);
return res;
}
}
/**
* 在前向插入一个非负整数,最大为 uint64::Max
* todo: 越界问题
* @param uint64_value
* @return
*/
public int prependNonNegativeInteger(long uint64_value){
byte[] bytes=buildNonNegativeIntegerArr(uint64_value);
return this.prependByteArray(bytes,new SizeT(bytes.length));
}
/**
* 在后向插入一个非负整数,最大为 uint64::Max
* todo: 越界问题
* @param uint64_value
* @return
*/
public int appendNonNegativeInteger(long uint64_value){
byte[] bytes=buildNonNegativeIntegerArr(uint64_value);
return this.appendByteArray(bytes,new SizeT(bytes.length));
}
/**
* @param array
* @param size