mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-06-18 06:00:25 +08:00
add packet test: DataTest
This commit is contained in:
@@ -38,6 +38,19 @@ public class CPacketTest {
|
||||
System.out.println("value: "+ Arrays.toString(cPacket.getValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* CPacket wireEncode:
|
||||
* [5, 61,
|
||||
* 50, 37,
|
||||
* 102, 19, 101, 17, 100, 4, 0, 109, 105, 110, 100, 4, 0, 112, 107, 117, 100, 3, 0, 115, 122,
|
||||
* 102, 14, 101, 12, 100, 4, 0, 110, 101, 116, 100, 4, 0, -25, -114, -117,
|
||||
* 52, 6, -52, 4, 1, 2, 3, 4,
|
||||
* 53, 12, 55, 10, -44, 8, 127, -1, -1, -1, -1, -1, -1, -1]
|
||||
* @throws EncoderException
|
||||
* @throws ComponentException
|
||||
* @throws PacketException
|
||||
* @throws BlockException
|
||||
*/
|
||||
@Test
|
||||
public void TestCPacket_WireEncode() throws EncoderException, ComponentException, PacketException, BlockException {
|
||||
MINPacket packet=new MINPacket();
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package packet;
|
||||
|
||||
import component.ComponentException;
|
||||
import component.Identifier;
|
||||
import encoding.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description:
|
||||
* @Version: 1.0.0
|
||||
* @Date: 21:19 2021/4/7
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class DataTest {
|
||||
@Test
|
||||
public void TestData_ToUri() throws ComponentException {
|
||||
Data data=new Data();
|
||||
Identifier name=new Identifier("/wefree/王");
|
||||
data.setName(name);
|
||||
System.out.println(data.getName().toUri());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data wireEncode:
|
||||
* [5, 53,
|
||||
* 50, 19,
|
||||
* 103, 17, 101, 15,
|
||||
* 100, 7, 0, 119, 101, 102, 114, 101, 101,
|
||||
* 100, 4, 0, -25, -114, -117,
|
||||
* 52, 16,
|
||||
* -46, 8, 127, -1, -1, -1, -1, -1, -1, -1,
|
||||
* -52, 4, -124, -35, -33, 25,
|
||||
* 53, 12, 54, 10, -45, 8, 127, -1, -1, -1, -1, -1, -1, -1]
|
||||
* @throws ComponentException
|
||||
* @throws EncoderException
|
||||
* @throws PacketException
|
||||
* @throws BlockException
|
||||
*/
|
||||
@Test
|
||||
public void TestData_WireEncode() throws ComponentException, EncoderException, PacketException, BlockException {
|
||||
Data data=new Data();
|
||||
data.freshnessPeriod.setFreshnessPeriod(Long.MAX_VALUE);
|
||||
byte[] value={(byte)132,(byte)221,(byte)223,(byte)25};
|
||||
data.payload.setValue(value);
|
||||
data.congestionMark.setCongestionLevel(Long.MAX_VALUE);
|
||||
Identifier name=new Identifier("/wefree/王");
|
||||
data.setName(name);
|
||||
|
||||
Encoder encoder=new Encoder();
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
System.out.println("encode res: "+data.wireEncode(encoder));
|
||||
byte[] buf=encoder.getBuffer();
|
||||
System.out.println("buf: "+ Arrays.toString(buf));
|
||||
|
||||
Block block=new Block(buf,false);
|
||||
System.out.println("block buf: "+Arrays.toString(block.getValue()));
|
||||
Data newData=new Data();
|
||||
System.out.println("decode res: "+newData.wireDecode(block));
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
System.out.println("encode res: "+newData.wireEncode(encoder));
|
||||
byte[] newbuf=encoder.getBuffer();
|
||||
System.out.println("newbuf: "+ Arrays.toString(newbuf));
|
||||
System.out.println("new uri: "+newData.toUri()
|
||||
+" , freshness; "+newData.freshnessPeriod.getFreshnessPeriod());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user