mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
Merge branch 'master' of gitee.com:willfree/min-dev-java
This commit is contained in:
commit
92408238aa
8 files changed
+327
-33
No files matched your search
@@ -277,7 +277,8 @@ public class Block {
|
||||
* @return
|
||||
*/
|
||||
public boolean isValid(){
|
||||
return this.tlvType.isEqual(TLV.TlvInvalid);
|
||||
// return this.tlvType.isEqual(TLV.TlvInvalid);
|
||||
return !this.tlvType.isEqual(TLV.TlvInvalid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,12 +8,13 @@ package encoding;
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class Encoder {
|
||||
private byte[] buffer;
|
||||
private int left; // 左指针 => 指向 Prepend* 操作下一个可以插入的位置
|
||||
private int right; // 右指针 => 指向 Append* 操作下一个可以插入的位置
|
||||
private boolean isInitial; // 是否初始化
|
||||
private boolean isEstimator;// 是否仅测量编码后的长度,而不实际进行编码
|
||||
private SizeT totalReserve; // 编码缓存数组的大小
|
||||
//TODO 便于测试暂时先将private属性改成public了
|
||||
public byte[] buffer;
|
||||
public int left; // 左指针 => 指向 Prepend* 操作下一个可以插入的位置
|
||||
public int right; // 右指针 => 指向 Append* 操作下一个可以插入的位置
|
||||
public boolean isInitial; // 是否初始化
|
||||
public boolean isEstimator;// 是否仅测量编码后的长度,而不实际进行编码
|
||||
public SizeT totalReserve; // 编码缓存数组的大小
|
||||
|
||||
/**
|
||||
* 编码测量初始化
|
||||
|
||||
@@ -49,13 +49,15 @@ public class ByteHelper {
|
||||
public static byte[] getLenBytes(byte[] buffer, VlInt start,VlInt len){
|
||||
int startInt=start.getVlIntValue2Int();
|
||||
int lenInt=len.getVlIntValue2Int();
|
||||
byte[] lenbytes=new byte[1];
|
||||
byte[] lenbytes=new byte[lenInt];
|
||||
// byte[] lenbytes=new byte[1];
|
||||
System.arraycopy(buffer,startInt,lenbytes,0,lenInt);
|
||||
return lenbytes;
|
||||
}
|
||||
public static byte[] getLenBytes(byte[] buffer, VlInt start,int len){
|
||||
int startInt=start.getVlIntValue2Int();
|
||||
byte[] lenbytes=new byte[1];
|
||||
byte[] lenbytes=new byte[len];
|
||||
// byte[] lenbytes=new byte[1];
|
||||
System.arraycopy(buffer,startInt,lenbytes,0,len);
|
||||
return lenbytes;
|
||||
}
|
||||
@@ -283,4 +285,25 @@ public class ByteHelper {
|
||||
System.out.println(b&0xff);
|
||||
}
|
||||
|
||||
// 便于测试,新添加两个public方法:
|
||||
// 无符号byte[]转int
|
||||
public static int new_byteArrayToInt(byte[]bytes){
|
||||
int value= 0;
|
||||
//由高位到低位
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
int offset= (bytes.length - 1 - i) * 8;
|
||||
value +=(bytes[i] & 0x000000ff) << offset; //往高位游
|
||||
}
|
||||
return value;
|
||||
}
|
||||
// 无符号byte[]转long
|
||||
public static long new_byteArrayToLong(byte[]bytes){
|
||||
int value= 0;
|
||||
//由高位到低位
|
||||
for (int i = 0; i < 8; i++) {
|
||||
int offset= (bytes.length - 1 - i) * 8;
|
||||
value +=(bytes[i] & 0x000000000000ff) << offset; //往高位游
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user