mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-06-13 18:08:35 +08:00
finished component: CanBePrefix
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
package component;
|
||||
|
||||
import encoding.*;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description: 表示内容兴趣包中的组件 CanBePrefix
|
||||
* @Version: 1.0.0
|
||||
* @Date: 11:33 2021/3/9
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class CanBePrefix implements TlvComponentBase,InitialAble, IEncodingAble {
|
||||
// 成员变量
|
||||
private boolean canBePrefix;
|
||||
|
||||
// 函数
|
||||
public void setCanBePrefix(boolean canBePrefix){
|
||||
this.canBePrefix=canBePrefix;
|
||||
}
|
||||
|
||||
public boolean getCanBePrefix(){
|
||||
return this.canBePrefix;
|
||||
}
|
||||
|
||||
// 接口实现-变量区
|
||||
private boolean initial=false;
|
||||
|
||||
// 接口实现-方法区
|
||||
@Override
|
||||
public void doInitial() {
|
||||
initial=true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitial() {
|
||||
return initial;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 CanBePrefix 线速编码为一个 TLV
|
||||
* @param encoder
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
// 这是一个存在性组件,所以如果值为false,则无需编码
|
||||
if(!this.canBePrefix){
|
||||
return 0;
|
||||
}
|
||||
|
||||
int totalLength=0;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
int tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvCanBePrefix));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
return totalLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 TLV Block 中解码一个 CanBePrefix
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
// 检查 Type 是否正确
|
||||
if(!TLV.expectType(block.getTlvType(),new VlInt(TLV.TlvCanBePrefix))){
|
||||
return false;
|
||||
}
|
||||
|
||||
this.canBePrefix=true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,10 @@ package component;
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public interface InitialAble {
|
||||
// 指示当前组件是否有初始化,如果没有初始化,且组件是可选组件,则无需编码
|
||||
boolean initial = false;
|
||||
// 指示当前组件是否有初始化,如果没有初始化,且组件是可选组件,则无需编码.
|
||||
// 接口中的变量都是final类型的(常量)。因此,如果需要一个变量,
|
||||
// 需要在实现该接口的类中定义该变量。
|
||||
// boolean initial = false;
|
||||
|
||||
// 将组件标记为已初始化
|
||||
public void doInitial();
|
||||
|
||||
Reference in New Issue
Block a user