mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
88 lines
2.0 KiB
Java
88 lines
2.0 KiB
Java
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;
|
|
this.doInitial();
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
// 这是一个存在性组件,所以存在则为 true
|
|
this.canBePrefix=true;
|
|
return true;
|
|
}
|
|
}
|