ByteHelper中getLenBytes错误解决

This commit is contained in:
zhaofeng233 committed 2021-03-13 23:18:52 +08:00
1 parent e622d92897
commit 8f75fad759
2 files changed
+13 -3

No files matched your search

+4 -2
View File
@@ -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;
}
+9 -1
View File
@@ -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