maven管理项目 + junit单元测试

This commit is contained in:
ghy committed 2021-03-02 21:35:29 +08:00
1 parent b07bf8a9f9
commit 5938be8893
9 files changed
+47 -1

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
package util;
import encoding.VlInt;
/*
* @Author: Wang Feng
* @Description:常用的数据类型转换。转无符号byte是重点
* @Version: 1.0.0
* @Date: 15:40 2021/3/2
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
public class ByteHelper {
/**
* 从byte[]数组指定开始位置获取第一个字节
* todo: start位置可能是大于int类型的数值
* @param buffer
* @param start
* @return
*/
public static byte getFirstByte(byte[] buffer, VlInt start){
int startInt=start.getVlIntValue2Int();
byte[] firstbyte=new byte[1];
System.arraycopy(buffer,startInt,firstbyte,0,1);
return firstbyte[0];
}
/**
* 从byte[]数组指定开始位置获取长度为len的字节数组
* todo: start位置可能是大于int类型的数值
* @param buffer
* @param start
* @return
*/
public static byte[] getLenBytes(byte[] buffer, VlInt start,VlInt len){
int startInt=start.getVlIntValue2Int();
int lenInt=len.getVlIntValue2Int();
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];
System.arraycopy(buffer,startInt,lenbytes,0,len);
return lenbytes;
}
/**
* 无符号字节转int
* @param b
* @return
*/
public static int unsignedbyte2int(byte b){
return (int) b;
}
}