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
@@ -57,7 +57,7 @@ public class MutableDangerousField implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
public int wireEncode(Encoder encoder) throws ComponentException {
|
||||
// 如果可变非受保护区没有任何子 TLV,则可以去掉可变非受保护区 TLV
|
||||
if(this.blocks.length()==0){
|
||||
return -1;
|
||||
@@ -67,7 +67,12 @@ public class MutableDangerousField implements TlvComponentBase, IEncodingAble {
|
||||
// 编码TLV-VALUE
|
||||
// 反向遍历,可以保证解码的时候正向输出
|
||||
for(int i=this.blocks.length()-1;i>=0;i++){
|
||||
int tmplen=encoder.prependBlock(this.blocks.getBlock(i));
|
||||
int tmplen= 0;
|
||||
try {
|
||||
tmplen = encoder.prependBlock(this.blocks.getBlock(i));
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("MutableDangerousField.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
@@ -75,14 +80,23 @@ public class MutableDangerousField implements TlvComponentBase, IEncodingAble {
|
||||
}
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
int tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
int tmplen= 0;
|
||||
try {
|
||||
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("MutableDangerousField.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvReadOnlyField));
|
||||
try {
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvReadOnlyField));
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("MutableDangerousField.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
@@ -97,15 +111,19 @@ public class MutableDangerousField implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
public boolean wireDecode(Block block) throws ComponentException {
|
||||
// 检查 Type 是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvReadOnlyField))){
|
||||
return false;
|
||||
}
|
||||
|
||||
// 解析子 TLV
|
||||
if(!block.parseSubElements()){
|
||||
return false;
|
||||
try {
|
||||
if(!block.parseSubElements()){
|
||||
return false;
|
||||
}
|
||||
} catch (BlockException e) {
|
||||
throw new ComponentException("MutableDangerousField.wireDecode: "+e.getMessage());
|
||||
}
|
||||
|
||||
this.blocks=block.getSubElements();
|
||||
|
||||
Reference in new issue
Block a user