mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-06-18 04:50:25 +08:00
finished component: IdentifierWrapper
This commit is contained in:
@@ -13,6 +13,9 @@ public class IdentifierWrapper implements TlvComponentBase, IEncodingAble {
|
||||
private Identifier identifier;
|
||||
private VlInt tlvType;
|
||||
|
||||
public IdentifierWrapper(){
|
||||
}
|
||||
|
||||
/**
|
||||
* 从一个 IdentifierWrapper 编码成的 TLV Block 中解析出一个 IdentifierWrapper
|
||||
*/
|
||||
@@ -24,31 +27,298 @@ public class IdentifierWrapper implements TlvComponentBase, IEncodingAble {
|
||||
if((block.getSubElements().length()!=1)&&block.getSubElements().getBlock(0).getType().isEqual(TLV.TlvIdentifier)){
|
||||
// todo: 错误处理
|
||||
}
|
||||
|
||||
this.tlvType=block.getType();
|
||||
this.identifier.buildIdentifierByBlock(block.getSubElements().getBlock(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义标识类型,根据标识的字符串标识创建一个自定义的标识
|
||||
* @Description:
|
||||
* // 1. 格式如下:
|
||||
* // CustomIdentifier = <自定义标识类型> TLV-LENGTH
|
||||
* // <Identifier>
|
||||
* @param tlvType
|
||||
* @param identifierString
|
||||
* @return
|
||||
*/
|
||||
public IdentifierWrapper createCustomIdentifierByString(VlInt tlvType,String identifierString){
|
||||
|
||||
public IdentifierWrapper(VlInt tlvType,String identifierString){
|
||||
if(TLV.isValidIdentifierType(tlvType)){
|
||||
// todo: 报错
|
||||
}
|
||||
this.tlvType=tlvType;
|
||||
this.identifier.buildIdentifierByString(identifierString);
|
||||
}
|
||||
|
||||
public IdentifierWrapper createCustomIdentifierByComponents(){
|
||||
|
||||
/**
|
||||
* 自定义标识类型,根据 components 创建一个自定义的标识
|
||||
* @Description:
|
||||
* // 1. 格式如下:
|
||||
* // CustomIdentifier = <自定义标识类型> TLV-LENGTH
|
||||
* // <Identifier>
|
||||
* @param tlvType
|
||||
* @param container
|
||||
* @return
|
||||
*/
|
||||
public IdentifierWrapper(VlInt tlvType,IdentifierComponentContainer container){
|
||||
if(TLV.isValidIdentifierType(tlvType)){
|
||||
// todo: 报错
|
||||
}
|
||||
this.tlvType=tlvType;
|
||||
this.identifier.buildIdentifierByComponents(container);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义标识类型,根据 TLV Block 创建一个自定义标识
|
||||
* @param tlvType
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
public IdentifierWrapper(VlInt tlvType,Block block){
|
||||
if(TLV.isValidIdentifierType(tlvType)){
|
||||
// todo: 报错
|
||||
}
|
||||
this.tlvType=tlvType;
|
||||
this.identifier.buildIdentifierByBlock(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据标识的字符串表示创建一个通用的身份标识
|
||||
* //
|
||||
* // @Description:
|
||||
* // 1. 格式如下:
|
||||
* // CommonIdentifier = 102 TLV-LENGTH
|
||||
* // <Identifier>
|
||||
* @param identifierString
|
||||
* @return
|
||||
*/
|
||||
public IdentifierWrapper createCommonIdentifierByString(String identifierString){
|
||||
IdentifierWrapper identifierWrapper=new IdentifierWrapper();
|
||||
identifierWrapper.tlvType=new VlInt(TLV.TlvIdentifierCommon);
|
||||
identifierWrapper.identifier.buildIdentifierByString(identifierString);
|
||||
return identifierWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据components构造一个通用的身份标识
|
||||
* //
|
||||
* // @Description:
|
||||
* // 1. 格式如下:
|
||||
* // CommonIdentifier = 102 TLV-LENGTH
|
||||
* // <Identifier>
|
||||
* @param container
|
||||
*/
|
||||
public IdentifierWrapper createCommonIdentifierByComponents(IdentifierComponentContainer container){
|
||||
IdentifierWrapper identifierWrapper=new IdentifierWrapper();
|
||||
identifierWrapper.tlvType=new VlInt(TLV.TlvIdentifierCommon);
|
||||
identifierWrapper.identifier.buildIdentifierByComponents(container);
|
||||
return identifierWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 TLV Block 构造一个通用的身份标识
|
||||
* //
|
||||
* // @Description:
|
||||
* // 1. 格式如下:
|
||||
* // CommonIdentifier = 102 TLV-LENGTH
|
||||
* // <Identifier>
|
||||
* // @param block 传递 Identifier Block,而非 IdentifierWrapper Block
|
||||
* @return
|
||||
*/
|
||||
public IdentifierWrapper createCommonIdentifierByBlock(Block block){
|
||||
IdentifierWrapper identifierWrapper=new IdentifierWrapper();
|
||||
identifierWrapper.tlvType=new VlInt(TLV.TlvIdentifierCommon);
|
||||
identifierWrapper.identifier.buildIdentifierByBlock(block);
|
||||
return identifierWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据标识的字符串表示创建一个内容兴趣标识
|
||||
* //
|
||||
* // @Description:
|
||||
* // 1. 格式如下:
|
||||
* // CommonIdentifier = 103 TLV-LENGTH
|
||||
* // <Identifier>
|
||||
* @param identifierString
|
||||
* @return
|
||||
*/
|
||||
public IdentifierWrapper createContentInterestIdentifierByString(String identifierString){
|
||||
IdentifierWrapper identifierWrapper=new IdentifierWrapper();
|
||||
identifierWrapper.tlvType=new VlInt(TLV.TlvIdentifierContentInterest);
|
||||
identifierWrapper.identifier.buildIdentifierByString(identifierString);
|
||||
return identifierWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据components构造一个内容兴趣标识
|
||||
* //
|
||||
* // @Description:
|
||||
* // 1. 格式如下:
|
||||
* // CommonIdentifier = 103 TLV-LENGTH
|
||||
* // <Identifier>
|
||||
* @param container
|
||||
* @return
|
||||
*/
|
||||
public IdentifierWrapper createContentInterestIdentifierByComponents(IdentifierComponentContainer container){
|
||||
IdentifierWrapper identifierWrapper=new IdentifierWrapper();
|
||||
identifierWrapper.tlvType=new VlInt(TLV.TlvIdentifierContentInterest);
|
||||
identifierWrapper.identifier.buildIdentifierByComponents(container);
|
||||
return identifierWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 TLV Block 构造一个内容兴趣标识
|
||||
* //
|
||||
* // @Description:
|
||||
* // 1. 格式如下:
|
||||
* // CommonIdentifier = 103 TLV-LENGTH
|
||||
* // <Identifier>
|
||||
* @param block 传递 Identifier Block,而非 IdentifierWrapper Block
|
||||
* @return
|
||||
*/
|
||||
public IdentifierWrapper createContentInterestIdentifierByBlock(Block block){
|
||||
IdentifierWrapper identifierWrapper=new IdentifierWrapper();
|
||||
identifierWrapper.tlvType=new VlInt(TLV.TlvIdentifierContentInterest);
|
||||
identifierWrapper.identifier.buildIdentifierByBlock(block);
|
||||
return identifierWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据标识的字符串表示创建一个内容数据标识
|
||||
* //
|
||||
* // @Description:
|
||||
* // 1. 格式如下:
|
||||
* // CommonIdentifier = 104 TLV-LENGTH
|
||||
* // <Identifier>
|
||||
* @param identifierString
|
||||
* @return
|
||||
*/
|
||||
public IdentifierWrapper createContentDataIdentifierByString(String identifierString){
|
||||
IdentifierWrapper identifierWrapper=new IdentifierWrapper();
|
||||
identifierWrapper.tlvType=new VlInt(TLV.TlvIdentifierContentData);
|
||||
identifierWrapper.identifier.buildIdentifierByString(identifierString);
|
||||
return identifierWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据components构造一个内容数据标识
|
||||
* //
|
||||
* // @Description:
|
||||
* // 1. 格式如下:
|
||||
* // CommonIdentifier = 104 TLV-LENGTH
|
||||
* // <Identifier>
|
||||
* @param container
|
||||
* @return
|
||||
*/
|
||||
public IdentifierWrapper createContentDataIdentifierByComponents(IdentifierComponentContainer container){
|
||||
IdentifierWrapper identifierWrapper=new IdentifierWrapper();
|
||||
identifierWrapper.tlvType=new VlInt(TLV.TlvIdentifierContentData);
|
||||
identifierWrapper.identifier.buildIdentifierByComponents(container);
|
||||
return identifierWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 TLV Block 构造一个内容数据标识
|
||||
* //
|
||||
* // @Description:
|
||||
* // 1. 格式如下:
|
||||
* // CommonIdentifier = 104 TLV-LENGTH
|
||||
* // <Identifier>
|
||||
* @param block 传递 Identifier Block,而非 IdentifierWrapper Block
|
||||
* @return
|
||||
*/
|
||||
public static IdentifierWrapper createContentDataIdentifierByBlock(Block block){
|
||||
IdentifierWrapper identifierWrapper=new IdentifierWrapper();
|
||||
identifierWrapper.tlvType=new VlInt(TLV.TlvIdentifierContentData);
|
||||
identifierWrapper.identifier.buildIdentifierByBlock(block);
|
||||
return identifierWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否有效
|
||||
* @return
|
||||
*/
|
||||
public boolean isValid(){
|
||||
return TLV.isValidIdentifierType(this.tlvType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 identifier 对象
|
||||
* @return
|
||||
*/
|
||||
public Identifier getIdentifier(){
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对 IdentifierWrapper 执行线速编码
|
||||
* //
|
||||
* // @Description:
|
||||
* // 1. 格式如下:
|
||||
* // IdentifierWrapper = TLV-TYPE TLV-LENGTH
|
||||
* // <Identifier>
|
||||
* @param encoder
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
return 0;
|
||||
int totalLength=0;
|
||||
|
||||
// 编码 TLV-VALUE
|
||||
int tmplen=this.identifier.wireEncode(encoder);
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen=encoder.prependVarNumber(this.tlvType);
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
return totalLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* 线速解码,从 TLV Block 中解码一个 IdentifierWrapper
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
return false;
|
||||
// 检查TLV值是否有效
|
||||
if(!TLV.isValidIdentifierType(block.getType())){
|
||||
return false;
|
||||
}
|
||||
// 解析子 TLV
|
||||
if(!block.parseSubElements()){
|
||||
return false;
|
||||
}
|
||||
// 判断是否有且仅有一个子TLV
|
||||
if(block.getSubElements().length()!=1){
|
||||
return false;
|
||||
}
|
||||
// 尝试将唯一的子TLV Block解析成一个 Identifier
|
||||
if(!this.identifier.buildIdentifierByBlock(block.getSubElements().getBlock(0))){
|
||||
return false;
|
||||
}
|
||||
this.tlvType=block.getType();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 IdentifierWrapper 表示成Uri 字符串
|
||||
* @return
|
||||
*/
|
||||
public String toUri(){
|
||||
return this.identifier.toUri();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user