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
@@ -43,25 +43,38 @@ public class CongestionMark implements TlvComponentBase,InitialAble, IEncodingAb
|
||||
* @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.congestionMark);
|
||||
int tmplen= 0;
|
||||
try {
|
||||
tmplen = encoder.prependNonNegativeInteger(this.congestionMark);
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("CongestionMark.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("CongestionMark.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen+=encoder.prependVarNumber(new VlInt(TLV.TlvCongestionMark));
|
||||
try {
|
||||
tmplen+=encoder.prependVarNumber(new VlInt(TLV.TlvCongestionMark));
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("CongestionMark.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
@@ -76,15 +89,19 @@ public class CongestionMark implements TlvComponentBase,InitialAble, IEncodingAb
|
||||
* @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.TlvCongestionMark))){
|
||||
return false;
|
||||
}
|
||||
|
||||
// 读取 CongestionMark
|
||||
long value= 0;
|
||||
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
|
||||
long value = 0;
|
||||
try {
|
||||
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
|
||||
} catch (TLVException | VlIntException e) {
|
||||
throw new ComponentException("CongestionMark.wireDecode: "+e.getMessage());
|
||||
}
|
||||
if(value<0){
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user