From 8f75fad759b54bbbdcbbdf194dc691da0b9ffa87 Mon Sep 17 00:00:00 2001 From: zhaofeng233 Date: Sat, 13 Mar 2021 23:18:25 +0800 Subject: [PATCH 1/8] =?UTF-8?q?ByteHelper=E4=B8=ADgetLenBytes=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/util/ByteHelper.java | 6 ++++-- src/test/java/util/ByteHelperTest.java | 10 +++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/util/ByteHelper.java b/src/main/java/util/ByteHelper.java index be71309..2475796 100644 --- a/src/main/java/util/ByteHelper.java +++ b/src/main/java/util/ByteHelper.java @@ -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; } diff --git a/src/test/java/util/ByteHelperTest.java b/src/test/java/util/ByteHelperTest.java index e6db963..689b53e 100644 --- a/src/test/java/util/ByteHelperTest.java +++ b/src/test/java/util/ByteHelperTest.java @@ -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 From e4c549fdb8a86b2790d64c662396800e5ec15e08 Mon Sep 17 00:00:00 2001 From: zhaofeng233 Date: Sun, 14 Mar 2021 00:10:23 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E5=8F=91=E7=8E=B0=E4=B8=A4=E5=A4=84?= =?UTF-8?q?=E6=96=B0=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/encoding/VlIntTest.java | 52 ++++++++++++++++++--------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/src/test/java/encoding/VlIntTest.java b/src/test/java/encoding/VlIntTest.java index 2f30a2e..b60f337 100644 --- a/src/test/java/encoding/VlIntTest.java +++ b/src/test/java/encoding/VlIntTest.java @@ -44,51 +44,71 @@ public class VlIntTest { public void getVlIntValue2Int() { //vlint(int)的size小于4时,测试是否能准确转为int输出 int a = 222; - int b = 22222222; + int a2 = 22222222; + byte[] b1 = new byte[]{0x00,0x7f, (byte) 0xff}; //32767 + byte[] b2 = new byte[]{0x00,(byte) 0x80, 0x00}; //32768 + byte[] b3 = new byte[]{0x00,(byte) 0xff, (byte) 0xff};//65535 VlInt vlInt_int1 = new VlInt(a); - VlInt vlInt_int2 = new VlInt(b); + VlInt vlInt_int2 = new VlInt(a2); + VlInt vlInt_b1 = new VlInt(b1); + VlInt vlInt_b2 = new VlInt(b2); + VlInt vlInt_b3 = new VlInt(b3); //测试size大小 assertTrue(vlInt_int1.size()<4); assertFalse(vlInt_int2.size()<4); //测试VlIntValue是否转为int assertEquals(vlInt_int1.getVlIntValue2Int(),a); + assertEquals(vlInt_b1.getVlIntValue2Int(),32767); + assertEquals(vlInt_b2.getVlIntValue2Int(),32768); + assertEquals(vlInt_b3.getVlIntValue2Int(),65535); } + //error:以bytes[]形式构造的VlInt,2^31-1 到 2^32-1之间的数会出错 @Test public void getVlIntValue2Long() { long l1 = new Long(0); long l2 = new Long(1); long l3 = new Long(4294967295L); //2^32-1 - long l4 = new Long(4294967296L); //2^32 + byte[] b1 = new byte[]{0x00,0x7f,(byte) 0xff,(byte) 0xff,(byte) 0xff};//2^31-1 + byte[] b2= new byte[]{0x00,(byte) 0x80,0x00,0x00,0x00};//2^31 VlInt vlInt_long1 = new VlInt(l1); // size = 1 VlInt vlInt_long2 = new VlInt(l2); // size = 1 VlInt vlInt_long3 = new VlInt(l3); // size = 5 - VlInt vlInt_long4 = new VlInt(l4); // size = 9 - - assertTrue(vlInt_long3.size()<8); - assertFalse(vlInt_long4.size()<8); + VlInt vlInt_long4 = new VlInt(b1); + VlInt vlInt_long5 = new VlInt(b2); + //以VlInt(long)形式构造的VlInt assertEquals(vlInt_long1.getVlIntValue2Long(),l1); assertEquals(vlInt_long2.getVlIntValue2Long(),l2); assertEquals(vlInt_long3.getVlIntValue2Long(),l3); + ///以VlInt(bytes[])形式构造的VlInt + assertEquals(vlInt_long4.getVlIntValue2Long(),2147483647L);//2^31-1 + assertEquals(vlInt_long5.getVlIntValue2Long(),2147483648L);//2^31 } + //error:以bytes[]形式构造的VlInt,在大于2^31-1的数会出错 @Test public void getVlIntValue() { - long l1 = new Long(4294967295L); //2^32-1 - long l2 = new Long(4294967296L); //2^32 + BigInteger b_0 = BigInteger.valueOf(2147483647L);//2^31-1 + BigInteger b_1 = BigInteger.valueOf(2147483648L);//2^31 BigInteger b = BigInteger.valueOf(4294967296L);//2^32 + //2^31-1 + byte[] b0 = new byte[]{0x00,0x00,0x00,0x00,0x00,0x7f,(byte) 0xff,(byte) 0xff,(byte) 0xff};//2147483647 + byte[] b1 = new byte[]{0x00,0x00,0x00,0x00,0x00,(byte) 0x80,0x00,0x00,0x00}; + //2^32-1 + byte[] b2 = new byte[]{0x00,0x00,0x00,0x00,0x00,(byte) 0xff,(byte) 0xff,(byte) 0xff,(byte) 0xff}; + byte[] b3 = new byte[]{0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00};//2^32 - VlInt vlInt_long = new VlInt(l1); - VlInt vlInt_long2 = new VlInt(l2); VlInt vlInt_bigInteger = new VlInt(b); - //判断size - assertFalse(vlInt_long.size()>=9); - assertTrue(vlInt_long2.size()>=9); - assertTrue(vlInt_bigInteger.size()>=9); - //判断值是否相等 + VlInt vlInt_b0 = new VlInt(b0); + VlInt vlInt_b1 = new VlInt(b1); + //以VlInt(BigInteger)形式构造的VlInt assertEquals(vlInt_bigInteger.getVlIntValue(),b); + ///以VlInt(bytes[])形式构造的VlInt + assertEquals(vlInt_b0.getVlIntValue(),b_0); + assertEquals(vlInt_b1.getVlIntValue(),b_1); + } @Test From a0aa95830356802f5b364bb930109a2a36946c59 Mon Sep 17 00:00:00 2001 From: zhaofeng233 Date: Sun, 14 Mar 2021 17:33:10 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E5=88=A4=E6=96=ADblock=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=9C=89=E6=95=88=E7=9A=84isValid()=E6=96=B9=E6=B3=95=20?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=BA=A0=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/encoding/Block.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/encoding/Block.java b/src/main/java/encoding/Block.java index 6cb00ce..f9816f4 100644 --- a/src/main/java/encoding/Block.java +++ b/src/main/java/encoding/Block.java @@ -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); } /** From ffa0b8640fc644f3ced78a23a2a57f8c628f8bc5 Mon Sep 17 00:00:00 2001 From: zhaofeng233 Date: Sun, 14 Mar 2021 17:35:00 +0800 Subject: [PATCH 4/8] =?UTF-8?q?ByteHelper=E6=96=B0=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=B0=86byteArray=E8=BD=AC=E6=8D=A2=E6=88=90?= =?UTF-8?q?int16=E7=9A=84=E6=96=B9=E6=B3=95=EF=BC=9AbyteArrayToInt16()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/util/ByteHelper.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/util/ByteHelper.java b/src/main/java/util/ByteHelper.java index 2475796..134bb48 100644 --- a/src/main/java/util/ByteHelper.java +++ b/src/main/java/util/ByteHelper.java @@ -94,6 +94,16 @@ public class ByteHelper { } return value; } + //无符号byte[2]转int + public static int byteArrayToInt16(byte[]bytes){ + int value= 0; + //由高位到低位 + for (int i = 0; i < 2; i++) { + int offset= (bytes.length - 1 - i) * 8; + value +=(bytes[i] & 0x000000ff) << offset; //往高位游 + } + return value; + } /** * 无符号long转byte[] From 43699e6c7cb03f04da15d3001f018d92b52c8f87 Mon Sep 17 00:00:00 2001 From: zhaofeng233 Date: Sun, 14 Mar 2021 17:44:34 +0800 Subject: [PATCH 5/8] =?UTF-8?q?Block=20=E6=B5=8B=E8=AF=95=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/encoding/BlockTest.java | 149 ++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 src/test/java/encoding/BlockTest.java diff --git a/src/test/java/encoding/BlockTest.java b/src/test/java/encoding/BlockTest.java new file mode 100644 index 0000000..4ebdff8 --- /dev/null +++ b/src/test/java/encoding/BlockTest.java @@ -0,0 +1,149 @@ +package encoding; + +import org.junit.Test; +import util.ByteHelper; + +import static org.junit.Assert.*; + +/* + * @Author: feng Zhao + * @Description: + * @Version: 1.0.0 + * @Date: 14:52 2021/3/14 + * @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 + */ + +public class BlockTest { + + @Test + public void TestCreateBlockByTypeLengthBuffer() { + byte[] buf = new byte[10000]; + Block block = Block.createBlockByTypeLengthBuffer(new VlInt(241), new VlInt(8000),ByteHelper.getLenBytes(buf, new VlInt(0),8000),true); + //测试type与size + assertEquals(block.getType().getVlIntValue2Int(),241); + assertEquals(block.getLength().getVlIntValue2Int(),8000); + + //测试rawBuf数据正确性 + //rawBuf[0] == 241 + byte[] rawBuf = block.getRaw(); + assertEquals(rawBuf[0],(byte)241); + // rawBuf[1:3] == 241 + int a = ByteHelper.byteArrayToInt16(ByteHelper.getLenBytes(rawBuf, new VlInt(1),2)); + assertEquals(a,241); + //rawBuf[3] == 241 + assertEquals(rawBuf[3],(byte) 241); + //rawBuf[4:6] == 8000 + int b = ByteHelper.byteArrayToInt16(ByteHelper.getLenBytes(rawBuf,new VlInt(4),2)); + assertEquals(b,8000); + //rawBuf.length == 8006 + assertEquals(rawBuf.length,8006); + + } + + //error:block.Size().size()错误。 + @Test + public void TestCreateBlockByBuffer() { + byte[] buf = new byte[10000]; + buf[0] = (byte)212; + buf[1] = (byte)241; + byte[] tmp = ByteHelper.uint16ToByteArray(8000); + System.arraycopy(tmp,0,buf,2,2); + + Block block = Block.createBlockByBuffer(ByteHelper.getLenBytes(buf,new VlInt(0),8004),true); + assertEquals(block.getType().getVlIntValue2Int(),212); + System.out.println("测试block.Size().size()"); + assertEquals(block.getLength().getVlIntValue2Int(),8000); + //block.Size()返回一个SizeT,再调用SizeT.size() + assertEquals(block.Size().size(),8004); + assertTrue(block.hasValue()); + } + + @Test + public void TestBuildByBlock(){ + //Block构造方法测试 + byte[] buf = new byte[10000]; + Block block1 = Block.createBlockByTypeLengthBuffer(new VlInt(241), new VlInt(8000),ByteHelper.getLenBytes(buf, new VlInt(0),8000),true); + Block block = new Block(block1); + //测试block数据正确性 + assertEquals(block.getType().getVlIntValue2Int(),241); + assertEquals(block.getLength().getVlIntValue2Int(),8000); + /*测试rawBuf数据正确性 + rawBuf[0] == 241 + rawBuf[1:3] == 241 + rawBuf[3] == 241 + rawBuf[4:6] == 8000 + rawBuf.length == 8006 + */ + byte[] rawBuf = block.getRaw(); + assertEquals(rawBuf[0],(byte)241); + int a = ByteHelper.byteArrayToInt16(ByteHelper.getLenBytes(rawBuf, new VlInt(1),2)); + assertEquals(a,241); + assertEquals(rawBuf[3],(byte) 241); + int b = ByteHelper.byteArrayToInt16(ByteHelper.getLenBytes(rawBuf,new VlInt(4),2)); + assertEquals(b,8000); + assertEquals(rawBuf.length,8006); + } + + @Test + public void TestBuildByTypeLengthBuffer(){ + //Block构造方法测试 + byte[] buf = new byte[10000]; + Block block = new Block(new VlInt(241),new VlInt(8000),ByteHelper.getLenBytes(buf,new VlInt(0),8000),true); + //测试block数据正确性 + assertEquals(block.getType().getVlIntValue2Int(),241); + assertEquals(block.getLength().getVlIntValue2Int(),8000); + /*测试rawBuf数据正确性 + rawBuf[0] == 241 + rawBuf[1:3] == 241 + rawBuf[3] == 241 + rawBuf[4:6] == 8000 + rawBuf.length == 8006 + */ + byte[] rawBuf = block.getRaw(); + assertEquals(rawBuf[0],(byte)241); + int a = ByteHelper.byteArrayToInt16(ByteHelper.getLenBytes(rawBuf, new VlInt(1),2)); + assertEquals(a,241); + assertEquals(rawBuf[3],(byte) 241); + int b = ByteHelper.byteArrayToInt16(ByteHelper.getLenBytes(rawBuf,new VlInt(4),2)); + assertEquals(b,8000); + assertEquals(rawBuf.length,8006); + } + + //error + //TODO 错误处理 + @Test + public void TestParseSubElements(){ + byte[] buf = new byte[10000]; + for (int i = 0; i < 240; i++) { + buf[i*8] = (byte)(i+1); + buf[i*8+1] = 6; + } + Block block = new Block(new VlInt(241),new VlInt(240*8),ByteHelper.getLenBytes(buf,new VlInt(0),240*8),true); + block.parseSubElements(); + //TODO 错误处理 + + ElementContainer elementContainer = block.getSubElements(); + //测试解析数据正确性 + for (int i = 0; i < elementContainer.length(); i++) { + assertEquals(elementContainer.getBlock(i).getType(),new VlInt(i+1)); + assertEquals(elementContainer.getBlock(i).getLength(),new VlInt(6)); + } + } + + //error + //TODO 没测完 + @Test + public void TestSubElements(){ + byte[] buf = new byte[10000]; + Block block = new Block(); + block.setType(new VlInt(7)); + for (int i = 0; i < 240; i++) { + Block b = Block.createBlockByTypeLengthBuffer(new VlInt(i+1),new VlInt(6),ByteHelper.getLenBytes(buf,new VlInt(0),6),true); + block.addElement(b); + } +// System.out.println("block.hasValue() = "+block.hasValue()); +// System.out.println("block.hasSubElement() = "+block.hasSubElement()); + ElementContainer elements = block.getSubElements(); + + } +} From 0e93a55428ff8d45b8946e57a511828902fcd9f7 Mon Sep 17 00:00:00 2001 From: zhaofeng233 Date: Mon, 15 Mar 2021 01:27:30 +0800 Subject: [PATCH 6/8] =?UTF-8?q?ByteHelper=E6=96=B0=E5=8F=91=E7=8E=B0?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/util/ByteHelper.java | 31 +++++++++++++++++--------- src/test/java/encoding/BlockTest.java | 12 +++++----- src/test/java/util/ByteHelperTest.java | 16 ++++++++----- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/main/java/util/ByteHelper.java b/src/main/java/util/ByteHelper.java index 134bb48..22eb1eb 100644 --- a/src/main/java/util/ByteHelper.java +++ b/src/main/java/util/ByteHelper.java @@ -94,16 +94,6 @@ public class ByteHelper { } return value; } - //无符号byte[2]转int - public static int byteArrayToInt16(byte[]bytes){ - int value= 0; - //由高位到低位 - for (int i = 0; i < 2; i++) { - int offset= (bytes.length - 1 - i) * 8; - value +=(bytes[i] & 0x000000ff) << offset; //往高位游 - } - return value; - } /** * 无符号long转byte[] @@ -295,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; + } } diff --git a/src/test/java/encoding/BlockTest.java b/src/test/java/encoding/BlockTest.java index 4ebdff8..b132d18 100644 --- a/src/test/java/encoding/BlockTest.java +++ b/src/test/java/encoding/BlockTest.java @@ -28,12 +28,12 @@ public class BlockTest { byte[] rawBuf = block.getRaw(); assertEquals(rawBuf[0],(byte)241); // rawBuf[1:3] == 241 - int a = ByteHelper.byteArrayToInt16(ByteHelper.getLenBytes(rawBuf, new VlInt(1),2)); + int a = ByteHelper.new_byteArrayToInt(ByteHelper.getLenBytes(rawBuf, new VlInt(1),2)); assertEquals(a,241); //rawBuf[3] == 241 assertEquals(rawBuf[3],(byte) 241); //rawBuf[4:6] == 8000 - int b = ByteHelper.byteArrayToInt16(ByteHelper.getLenBytes(rawBuf,new VlInt(4),2)); + int b = ByteHelper.new_byteArrayToInt(ByteHelper.getLenBytes(rawBuf,new VlInt(4),2)); assertEquals(b,8000); //rawBuf.length == 8006 assertEquals(rawBuf.length,8006); @@ -76,10 +76,10 @@ public class BlockTest { */ byte[] rawBuf = block.getRaw(); assertEquals(rawBuf[0],(byte)241); - int a = ByteHelper.byteArrayToInt16(ByteHelper.getLenBytes(rawBuf, new VlInt(1),2)); + int a = ByteHelper.new_byteArrayToInt(ByteHelper.getLenBytes(rawBuf, new VlInt(1),2)); assertEquals(a,241); assertEquals(rawBuf[3],(byte) 241); - int b = ByteHelper.byteArrayToInt16(ByteHelper.getLenBytes(rawBuf,new VlInt(4),2)); + int b = ByteHelper.new_byteArrayToInt(ByteHelper.getLenBytes(rawBuf,new VlInt(4),2)); assertEquals(b,8000); assertEquals(rawBuf.length,8006); } @@ -101,10 +101,10 @@ public class BlockTest { */ byte[] rawBuf = block.getRaw(); assertEquals(rawBuf[0],(byte)241); - int a = ByteHelper.byteArrayToInt16(ByteHelper.getLenBytes(rawBuf, new VlInt(1),2)); + int a = ByteHelper.new_byteArrayToInt(ByteHelper.getLenBytes(rawBuf, new VlInt(1),2)); assertEquals(a,241); assertEquals(rawBuf[3],(byte) 241); - int b = ByteHelper.byteArrayToInt16(ByteHelper.getLenBytes(rawBuf,new VlInt(4),2)); + int b = ByteHelper.new_byteArrayToInt(ByteHelper.getLenBytes(rawBuf,new VlInt(4),2)); assertEquals(b,8000); assertEquals(rawBuf.length,8006); } diff --git a/src/test/java/util/ByteHelperTest.java b/src/test/java/util/ByteHelperTest.java index 689b53e..0b8c1d5 100644 --- a/src/test/java/util/ByteHelperTest.java +++ b/src/test/java/util/ByteHelperTest.java @@ -39,7 +39,7 @@ import static org.junit.Assert.*; assertEquals(firstbyte,test[0]); } - //error + @Test public void getLenBytes() { byte[] buffer = new byte[]{0x00,0x00,0x01, (byte) 0xff}; //255 @@ -306,7 +306,7 @@ import static org.junit.Assert.*; assertEquals(a9,65535); } - //error + @Test public void uint16ToByteArray() { ByteHelper byteHelper = new ByteHelper(); @@ -376,7 +376,7 @@ import static org.junit.Assert.*; assertEquals(a9,65535); } - //error + @Test public void uint32ToLong() { byte[] b1 = new byte[]{0x00,0x00,0x00,0x00}; //0 @@ -423,7 +423,7 @@ import static org.junit.Assert.*; } - //error + @Test public void uint32ToByteArray() { byte[] b1 = new byte[]{0x00,0x00,0x00,0x00}; //0 @@ -472,7 +472,7 @@ import static org.junit.Assert.*; assertArrayEquals(a13,b13); } - //error + //todo 大于2^64次方无法表示 @Test public void uint64ToLong() { @@ -493,7 +493,11 @@ import static org.junit.Assert.*; byte[] b15 = new byte[]{0x7f,(byte) 0xff,(byte) 0xff,(byte) 0xff,(byte) 0xff,(byte) 0xff,(byte) 0xff,(byte) 0xff};//9223372036854775807 byte[] b16 = new byte[]{(byte) 0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00};//9223372036854775808 byte[] b17 = new byte[]{(byte) 0xff,(byte) 0xff,(byte) 0xff,(byte) 0xff,(byte) 0xff,(byte) 0xff,(byte) 0xff,(byte) 0xff};//18446744073709551615 + + byte[] b = new byte[]{(byte)0,(byte)0,(byte)0,(byte)0,(byte)0,(byte)0,(byte)0,(byte)1};//1 ByteHelper byteHelper = new ByteHelper(); + long a = byteHelper.uint64ToLong(b); + assertEquals(a,1); // byte[] b_test = new byte[]{0x00,0x00,0x00,0x00,(byte) 0x80,0x00,0x00,0x01};//2147483649 // long a_test = byteHelper.uint64ToLong(b_test); @@ -538,7 +542,7 @@ import static org.junit.Assert.*; } - //error + //todo 大于2^64次方无法表示 @Test public void uint64ToByteArray() { From 928f299713e25d29a294d310ce8cd5b195a8067f Mon Sep 17 00:00:00 2001 From: zhaofeng233 Date: Mon, 15 Mar 2021 01:29:44 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E4=B8=BA=E4=BA=86=E4=BE=BF=E4=BA=8E?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=9A=82=E6=97=B6=E5=85=88=E5=B0=86Encoder?= =?UTF-8?q?=E4=B8=AD=E7=9A=84private=E5=B1=9E=E6=80=A7=E6=94=B9=E6=88=90pu?= =?UTF-8?q?blic=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/encoding/Encoder.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/encoding/Encoder.java b/src/main/java/encoding/Encoder.java index cee4bf6..cb7d16d 100644 --- a/src/main/java/encoding/Encoder.java +++ b/src/main/java/encoding/Encoder.java @@ -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; // 编码缓存数组的大小 /** * 编码测量初始化 From 227d10a3913f279f525d0b86a6e7dbf00e873ccb Mon Sep 17 00:00:00 2001 From: ghy Date: Mon, 15 Mar 2021 10:07:19 +0800 Subject: [PATCH 8/8] rollback pom.xml & .gitignore , don't DELETE it!!!!!! --- .gitignore | 1 - pom.xml | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 pom.xml diff --git a/.gitignore b/.gitignore index 369dd5c..3191068 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ .idea/ .git/ out/ -pom.xml min-dev-java.iml target log/ \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..115f598 --- /dev/null +++ b/pom.xml @@ -0,0 +1,89 @@ + + + 4.0.0 + + min + min-dev-java + 1.0 + + + + + src/main/resources + + **/* + + + + + + + + + + junit + junit + 4.12 + test + + + + org.bouncycastle + bcprov-jdk15on + 1.65 + + + org.bouncycastle + bcpkix-jdk15on + 1.65 + + + + + ch.qos.logback + logback-classic + 1.2.3 + + + + + + commons-codec + commons-codec + 1.15 + + + + + + com.fasterxml.jackson.core + jackson-core + 2.2.3 + + + + com.fasterxml.jackson.core + jackson-annotations + 2.2.3 + + + + com.fasterxml.jackson.core + jackson-databind + 2.2.3 + + + + + + + org.mapdb + mapdb + 3.0.8 + + + + + \ No newline at end of file