add error handle: ComponentException & PacketException

This commit is contained in:
free will committed 2021-03-24 11:14:54 +08:00
1 parent d7f063cbb9
commit 7bf0906291
35 files changed
+955 -362

No files matched your search

+17 -7
View File
@@ -63,25 +63,38 @@ public class Payload implements TlvComponentBase,InitialAble, 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.prependByteArray(this.value,new SizeT(this.value.length));
int tmplen= 0;
try {
tmplen = encoder.prependByteArray(this.value,new SizeT(this.value.length));
} catch (EncoderException e) {
throw new ComponentException("Payload.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("Payload.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
// 编码 TLV-TYPE
tmplen+=encoder.prependVarNumber(new VlInt(TLV.TlvPayload));
try {
tmplen+=encoder.prependVarNumber(new VlInt(TLV.TlvPayload));
} catch (EncoderException e) {
throw new ComponentException("Payload.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
@@ -98,9 +111,6 @@ public class Payload implements TlvComponentBase,InitialAble, IEncodingAble {
}
// 存储Value
// int len=block.getLength().getVlIntValue2Int();
// byte[] bytes=new byte[len];
// System.arraycopy(block.getValue(),0,bytes,0,len);
this.setValue(block.getValue());
return true;
}