refresh test: ttl,etc...

This commit is contained in:
free will committed 2021-03-31 10:44:47 +08:00
1 parent dc060c2fc2
commit fafde2b015
14 files changed
+307 -347

No files matched your search

+37 -47
View File
@@ -44,64 +44,54 @@ public class HopLimit implements TlvComponentBase,InitialAble, IEncodingAble {
*/
@Override
public int wireEncode(Encoder encoder) throws ComponentException {
int totalLength=0;
// 编码 TLV-VALUE
int tmplen= 0;
try {
tmplen = encoder.prependNonNegativeInteger(this.hopLimit);
int totalLength = 0;
// 编码 TLV-VALUE
int tmplen = encoder.prependNonNegativeInteger(this.hopLimit);
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvHopLimit));
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
return totalLength;
} catch (EncoderException e) {
throw new ComponentException("HopLimit.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
// 编码 TLV-LENGTH
try {
tmplen+=encoder.prependVarNumber(new VlInt(totalLength));
} catch (EncoderException e) {
throw new ComponentException("HopLimit.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
// 编码 TLV-TYPE
try {
tmplen+=encoder.prependVarNumber(new VlInt(TLV.TlvHopLimit));
} catch (EncoderException e) {
throw new ComponentException("HopLimit.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
return totalLength;
}
@Override
public boolean wireDecode(Block block) throws ComponentException {
// 检查 Type 是否正确
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvHopLimit))){
return false;
}
// 读取 HopLimit
long value= 0;
try {
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
// 检查 Type 是否正确
if (!TLV.expectType(block.getType(), new VlInt(TLV.TlvHopLimit))) {
return false;
}
// 读取 HopLimit
long value = TLV.readNonNegativeInteger(block.getValue(), 0, block.getLength().getVlIntValue2Int());
if (value < 0) {
return false;
}
this.setHopLimit(value);
return true;
} catch (TLVException | VlIntException e) {
throw new ComponentException("HopLimit.wireDecode: "+e.getMessage());
}
if(value<0){
return false;
}
this.setHopLimit(value);
return true;
}
}