mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
error handle to all: EncoderException
This commit is contained in:
1 parent
5fc080ca6c
commit
8cf6ed24c9
34 files changed
+700
-233
No files matched your search
@@ -22,7 +22,7 @@ public class TTL implements IEncodingAble {
|
||||
public TTL(){
|
||||
}
|
||||
|
||||
public TTL(Block block){
|
||||
public TTL(Block block) throws VlIntException {
|
||||
buildTTLByBlock(block);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class TTL implements IEncodingAble {
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
public boolean buildTTLByBlock(Block block){
|
||||
public boolean buildTTLByBlock(Block block) throws VlIntException {
|
||||
return this.wireDecode(block);
|
||||
}
|
||||
|
||||
@@ -57,26 +57,26 @@ public class TTL implements IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
int totalLength=0;
|
||||
// 编码 TLV-VALUE
|
||||
int tmpLen=encoder.prependNonNegativeInteger(this.ttl);
|
||||
if(tmpLen==0){
|
||||
return 0;
|
||||
if(tmpLen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmpLen;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmpLen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmpLen==0){
|
||||
return 0;
|
||||
if(tmpLen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmpLen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmpLen=encoder.prependVarNumber(new VlInt(TLV.TlvTTL));
|
||||
if(tmpLen==0){
|
||||
return 0;
|
||||
if(tmpLen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmpLen;
|
||||
|
||||
@@ -89,17 +89,17 @@ public class TTL implements IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
// 检查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 (VlIntException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
if(value<0){
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user