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
@@ -15,11 +15,11 @@ public class TTL implements IEncodingAble {
|
||||
* todo: 后台使用的uint64,故这里用long表示,则理论上可能越界
|
||||
* // @Description:
|
||||
* 1. 格式如下:
|
||||
* TTL = TTL-TYPE TLV-LENGTH NonNegativeInteger
|
||||
*/
|
||||
* TTL = TTL-TYPE TLV-LENGTH NonNegativeInteger
|
||||
*/
|
||||
private long ttl;
|
||||
|
||||
public TTL(){
|
||||
public TTL() {
|
||||
}
|
||||
|
||||
public TTL(Block block) throws ComponentException {
|
||||
@@ -28,6 +28,7 @@ public class TTL implements IEncodingAble {
|
||||
|
||||
/**
|
||||
* 根据 TLV Block 初始化一个 TTL
|
||||
*
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
@@ -37,86 +38,80 @@ public class TTL implements IEncodingAble {
|
||||
|
||||
/**
|
||||
* 获取 TTL 值
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long ttl(){
|
||||
public long ttl() {
|
||||
return this.ttl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 TTL 值
|
||||
*
|
||||
* @param ttl
|
||||
*/
|
||||
public void setTtl(long ttl){
|
||||
this.ttl=ttl;
|
||||
public void setTtl(long ttl) {
|
||||
this.ttl = ttl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 TTL 线速编码为一个 TLV
|
||||
*
|
||||
* @param encoder
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) throws ComponentException {
|
||||
int totalLength=0;
|
||||
// 编码 TLV-VALUE
|
||||
int tmpLen= 0;
|
||||
try {
|
||||
tmpLen = encoder.prependNonNegativeInteger(this.ttl);
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("TTL.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmpLen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmpLen;
|
||||
int totalLength = 0;
|
||||
// 编码 TLV-VALUE
|
||||
int tmpLen = encoder.prependNonNegativeInteger(this.ttl);
|
||||
if (tmpLen <= 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmpLen;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
try {
|
||||
tmpLen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("TTL.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmpLen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmpLen;
|
||||
// 编码 TLV-LENGTH
|
||||
tmpLen = encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if (tmpLen <= 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmpLen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
try {
|
||||
tmpLen=encoder.prependVarNumber(new VlInt(TLV.TlvTTL));
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("TTL.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmpLen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmpLen;
|
||||
// 编码 TLV-TYPE
|
||||
tmpLen = encoder.prependVarNumber(new VlInt(TLV.TlvTTL));
|
||||
if (tmpLen <= 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmpLen;
|
||||
|
||||
return totalLength;
|
||||
return totalLength;
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("TTL.wireEncode: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 TLV Block 中解码出一个 TTL
|
||||
*
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) throws ComponentException {
|
||||
// 检查Type是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvTTL))){
|
||||
return false;
|
||||
}
|
||||
long value= 0;
|
||||
try {
|
||||
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
|
||||
// 检查Type是否正确
|
||||
if (!TLV.expectType(block.getType(), new VlInt(TLV.TlvTTL))) {
|
||||
return false;
|
||||
}
|
||||
long value = TLV.readNonNegativeInteger(block.getValue(), 0, block.getLength().getVlIntValue2Int());
|
||||
if (value < 0) {
|
||||
return false;
|
||||
}
|
||||
this.ttl = value;
|
||||
return true;
|
||||
} catch (TLVException | VlIntException e) {
|
||||
throw new ComponentException("TTL.wireDecode: "+e.getMessage());
|
||||
throw new ComponentException("TTL.wireDecode: " + e.getMessage());
|
||||
}
|
||||
if(value<0){
|
||||
return false;
|
||||
}
|
||||
this.ttl=value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user