mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
add error handle: ComponentException & PacketException
This commit is contained in:
1 parent
d7f063cbb9
commit
7bf0906291
35 files changed
+955
-362
No files matched your search
@@ -22,7 +22,7 @@ public class TTL implements IEncodingAble {
|
||||
public TTL(){
|
||||
}
|
||||
|
||||
public TTL(Block block) throws VlIntException {
|
||||
public TTL(Block block) throws ComponentException {
|
||||
buildTTLByBlock(block);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class TTL implements IEncodingAble {
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
public boolean buildTTLByBlock(Block block) throws VlIntException {
|
||||
public boolean buildTTLByBlock(Block block) throws ComponentException {
|
||||
return this.wireDecode(block);
|
||||
}
|
||||
|
||||
@@ -57,24 +57,37 @@ public class TTL implements IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
public int wireEncode(Encoder encoder) throws ComponentException {
|
||||
int totalLength=0;
|
||||
// 编码 TLV-VALUE
|
||||
int tmpLen=encoder.prependNonNegativeInteger(this.ttl);
|
||||
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;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmpLen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
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-TYPE
|
||||
tmpLen=encoder.prependVarNumber(new VlInt(TLV.TlvTTL));
|
||||
try {
|
||||
tmpLen=encoder.prependVarNumber(new VlInt(TLV.TlvTTL));
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("TTL.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmpLen<=0){
|
||||
return -1;
|
||||
}
|
||||
@@ -89,17 +102,17 @@ public class TTL implements IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
public boolean wireDecode(Block block) throws ComponentException {
|
||||
// 检查Type是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvTTL))){
|
||||
return false;
|
||||
}
|
||||
long value= 0;
|
||||
// try {
|
||||
try {
|
||||
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
|
||||
// } catch (VlIntException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
} catch (TLVException | VlIntException e) {
|
||||
throw new ComponentException("TTL.wireDecode: "+e.getMessage());
|
||||
}
|
||||
if(value<0){
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user