mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
finished encoder
This commit is contained in:
1 parent
4c1887bbc5
commit
6fddbff833
4 files changed
+131
-16
No files matched your search
@@ -7,7 +7,7 @@ import static java.lang.Math.pow;
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description:变长无符号整型,用于表示TLV中的T和L
|
||||
* todo: 本类需要在VlInt经过彻底测试之后,再进行完善。或可直接继承vlint
|
||||
* todo: 本类需要在VlInt经过彻底测试之后,再进行完善。或可直接继承vlint,或可内包装一个VlInt.
|
||||
* @Version: 1.0.0
|
||||
* @Date: 18:13 2021/3/1
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
@@ -17,13 +17,15 @@ public class SizeT {
|
||||
private byte[] VlIntBytes;
|
||||
// 变长整数表示的真实数值
|
||||
private BigInteger VlIntValue;
|
||||
// 变长整数的长度: 1 3 5 9 ...
|
||||
private int size;
|
||||
|
||||
/**
|
||||
* 测量一个变长整型实际用几个字节表示
|
||||
* @return
|
||||
*/
|
||||
public int SizeOfVarNumber(){
|
||||
return SizeOfVarNumber(this.VlIntValue);
|
||||
public int size(){
|
||||
return this.size;
|
||||
}
|
||||
private static int SizeOfVarNumber(BigInteger bigInteger){
|
||||
if(bigInteger.compareTo(BigInteger.valueOf(Long.parseLong("241"))) < 0){
|
||||
@@ -48,6 +50,12 @@ public class SizeT {
|
||||
this.VlIntValue=vlintBytes2bigInteger(bytes);
|
||||
}
|
||||
|
||||
public SizeT(VlInt vlInt){
|
||||
this.VlIntBytes=vlInt.getVlIntBytes();
|
||||
this.VlIntValue=vlInt.getVlIntValue();
|
||||
this.size = vlInt.size();
|
||||
}
|
||||
|
||||
public SizeT(BigInteger bigInteger){
|
||||
this.VlIntValue=bigInteger;
|
||||
this.VlIntBytes=bigInteger2vlintBytes(bigInteger);
|
||||
@@ -63,6 +71,10 @@ public class SizeT {
|
||||
return new SizeT(bigInteger);
|
||||
}
|
||||
|
||||
public byte[] getVlIntBytes(){
|
||||
return this.VlIntBytes;
|
||||
}
|
||||
|
||||
// todo:传入一个int,将它解析成一个VlInt
|
||||
public SizeT(int i){
|
||||
this.VlIntValue=new BigInteger(String.valueOf(i));
|
||||
@@ -78,7 +90,7 @@ public class SizeT {
|
||||
|
||||
// 将vlint转为一个int输出:需要判断size是不是小于4(1 or 3)
|
||||
public int getVlIntValue2Int(){
|
||||
if(this.SizeOfVarNumber()<4){
|
||||
if(this.size()<4){
|
||||
return VlIntValue.intValue();
|
||||
}
|
||||
return Integer.parseInt(null);
|
||||
@@ -86,7 +98,7 @@ public class SizeT {
|
||||
|
||||
// 将vlint转为一个long输出:需要判断size是不是小于8(5)
|
||||
public long getVlIntValue2Long(){
|
||||
if(this.SizeOfVarNumber()<8){
|
||||
if(this.size()<8){
|
||||
return VlIntValue.longValue();
|
||||
}
|
||||
return Long.parseLong(null);
|
||||
@@ -94,7 +106,7 @@ public class SizeT {
|
||||
|
||||
// 将vlint转为一个biginteger输出:需要判断size是不是等于9(9)
|
||||
public BigInteger getVlIntValue(){
|
||||
if(this.SizeOfVarNumber()>=9){
|
||||
if(this.size()>=9){
|
||||
return VlIntValue;
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in new issue
Block a user