mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
refresh test: ttl,etc...
This commit is contained in:
1 parent
dc060c2fc2
commit
fafde2b015
14 files changed
+307
-347
No files matched your search
@@ -9,7 +9,7 @@ import encoding.*;
|
||||
* @Date: 16:30 2021/3/9
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class MustBeRefresh implements TlvComponentBase,InitialAble, IEncodingAble {
|
||||
public class MustBeRefresh implements TlvComponentBase, InitialAble, IEncodingAble {
|
||||
// 成员变量
|
||||
private boolean mustBeRefresh;
|
||||
|
||||
@@ -24,12 +24,12 @@ public class MustBeRefresh implements TlvComponentBase,InitialAble, IEncodingAbl
|
||||
}
|
||||
|
||||
// 接口实现-变量区
|
||||
private boolean initial=false;
|
||||
private boolean initial = false;
|
||||
|
||||
// 接口实现-方法区
|
||||
@Override
|
||||
public void doInitial() {
|
||||
initial=true;
|
||||
initial = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,58 +39,56 @@ public class MustBeRefresh implements TlvComponentBase,InitialAble, IEncodingAbl
|
||||
|
||||
/**
|
||||
* 将 MustBeRefresh 线速编码为一个 TLV
|
||||
*
|
||||
* @param encoder
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) throws ComponentException {
|
||||
// 这是一个存在性组件,所以如果值为false,则无需编码
|
||||
if(!this.mustBeRefresh){
|
||||
return -1;
|
||||
}
|
||||
|
||||
int totalLength=0;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
int tmplen= 0;
|
||||
try {
|
||||
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("MustBeRefresh.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
// 这是一个存在性组件,所以如果值为false,则无需编码
|
||||
if (!this.mustBeRefresh) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
try {
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvMustBeRefresh));
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("MustBeRefresh.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
int totalLength = 0;
|
||||
|
||||
return totalLength;
|
||||
// 编码 TLV-LENGTH
|
||||
int tmplen = encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if (tmplen <= 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvMustBeRefresh));
|
||||
if (tmplen <= 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmplen;
|
||||
|
||||
return totalLength;
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("MustBeRefresh.wireEncode: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 TLV Block 中解码出一个 MustBeRefresh
|
||||
*
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
// 检查 Type 是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvMustBeRefresh))){
|
||||
if (!TLV.expectType(block.getType(), new VlInt(TLV.TlvMustBeRefresh))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 这是一个存在性组件,所以存在则为 true
|
||||
this.mustBeRefresh=true;
|
||||
this.mustBeRefresh = true;
|
||||
this.doInitial();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user