writting component: Identifier

This commit is contained in:
free will
2021-03-10 21:23:01 +08:00
parent 8182946c49
commit 298b804693
3 changed files with 107 additions and 7 deletions
+94
View File
@@ -0,0 +1,94 @@
package component;
import encoding.Block;
import encoding.Encoder;
import encoding.IEncodingAble;
import java.util.List;
/*
* @Author: Wang Feng
* @Description: 标识一个MIN网络标识
// 1. 身份标识为由单个名称组件组成的平面标识
// 2. 内容标识为一到多个名称组件组成的层级化标识
// 3. 包格式如下:
// Identifier = 101 TLV-LENGTH
// *IdentifierComponent
* @Version: 1.0.0
* @Date: 17:34 2021/3/10
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
*/
class IdentifierComponentContainer{
private List<IdentifierComponent> identifierComponents;
}
public class Identifier implements TlvComponentBase, IEncodingAble {
private IdentifierComponentContainer components;
/**
* 根据一个 TLV Block 创建一个Identifier
* @param block
*/
public Identifier(Block block){
this.buildIdentifierByBlock(block);
}
/**
* 根据标识的字符串标识创建一个标识
* @param identifierString
*/
public Identifier(String identifierString){
this.buildIdentifierByString(identifierString);
}
/**
* 根据components构造一个Identifier
* @param container
*/
public Identifier(IdentifierComponentContainer container){
this.buildIdentifierByComponents(container);
}
/**
* 根据一个 TLV Block 初始化当前Identifier
* @param block
*/
public boolean buildIdentifierByBlock(Block block){
// 如果不存在子 TLV 则不可能是一个 Identifier
if(!block.parseSubElements()){
return false;
}
if(block.getSubElements().length()<1){
return false;
}
return this.wireDecode(block);
}
/**
* 根据标识字符串初始化当前Identifier
* @param identifierString
* @return
*/
public boolean buildIdentifierByString(String identifierString){
if((identifierString.length()<=0)||(!identifierString.startsWith("/"))){
return false;
}
String[] componentStrings=identifierString.split("/");
IdentifierComponentContainer identifierComponentContainer=new IdentifierComponentContainer();
//...
return true;
}
@Override
public int wireEncode(Encoder encoder) {
return 0;
}
@Override
public boolean wireDecode(Block block) {
return false;
}
}
@@ -3,6 +3,7 @@ package component;
/*
* @Author: Wang Feng
* @Description: 名称组件
* todo: toUri()函数待完善
* @Version: 1.0.0
* @Date: 21:26 2021/3/9
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
@@ -102,10 +103,8 @@ public class IdentifierComponent implements TlvComponentBase, IEncodingAble {
* @param block
* @return
*/
public static IdentifierComponent createIdentifierComponentByBlock(Block block){
IdentifierComponent identifierComponent=new IdentifierComponent(0);
identifierComponent.wireDecode(block);
return identifierComponent;
public IdentifierComponent(Block block){
this.wireDecode(block);
}
/**
+10 -3
View File
@@ -22,8 +22,15 @@ public class HumanImpl implements God,Animal {
// HumanImpl h=new HumanImpl();
// h.sayHi();
// h.makeWorld();
String ss="hello";
System.out.println(ss.length());
System.out.println(ss.getBytes().length);
// String ss="hello";
// System.out.println(ss.length());
// System.out.println(ss.getBytes().length);
String[] i="/1/wefree/a.avi".split("/");
System.out.println("-------------");
for (int j = 0; j < i.length; j++) {
System.out.println(i[j]);
}
System.out.println("-------------");
// System.out.println();
}
}