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

+26 -1
View File
@@ -117,7 +117,32 @@ public class TLV {
return tlvType;
}
// todo:从字节数组的指定位置中读取一个非负整型
/**
* 从字节数组的指定位置中读取一个非负整型
* todo: 越界问题
*/
public static long readNonNegativeInteger(byte[] buffer,int start,int end){
if(start==end){
return 0;
}
if((start<0)||(end>buffer.length)){
return 0;
}
int len=end-start;
byte[] bytes=new byte[len];
System.arraycopy(buffer,start,bytes,0,len);
if(len==1){
return ByteHelper.uint8ToLong(buffer[start]);
}else if(len==2){
return ByteHelper.uint16ToLong(bytes);
}else if(len==4){
return ByteHelper.uint32ToLong(bytes);
}else if(len==8){
return ByteHelper.uint64ToLong(bytes);
}else{
return 0;
}
}
/**
* 检查某个type值是否是指定的 TLV-TYPE