mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
ByteHelper中getLenBytes错误解决
This commit is contained in:
1 parent
e622d92897
commit
8f75fad759
2 files changed
+13
-3
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import static org.junit.Assert.*;
|
||||
assertArrayEquals(b2,test2);
|
||||
}
|
||||
|
||||
//error
|
||||
//todo:对start值进行限定,应当小于Byte数组的length
|
||||
@Test
|
||||
public void getFirstByte() {
|
||||
byte[] b0 = new byte[]{0x00,0x00,0x01};
|
||||
@@ -42,6 +42,14 @@ import static org.junit.Assert.*;
|
||||
//error
|
||||
@Test
|
||||
public void getLenBytes() {
|
||||
byte[] buffer = new byte[]{0x00,0x00,0x01, (byte) 0xff}; //255
|
||||
byte[] test = new byte[]{0x00,0x00,0x01};
|
||||
VlInt start = new VlInt(0);
|
||||
VlInt len = new VlInt(3);
|
||||
byte[]b1 = ByteHelper.getLenBytes(buffer,start,len);
|
||||
byte[] b2= ByteHelper.getLenBytes(buffer,start,3);
|
||||
assertArrayEquals(test,b1);
|
||||
assertArrayEquals(test,b2);
|
||||
}
|
||||
|
||||
// @Test
|
||||
|
||||
Reference in new issue
Block a user