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
@@ -27,7 +27,7 @@ public class SignatureValue implements TlvComponentBase, IEncodingAble {
|
||||
* 根据 TLV Block 创建一个 SignatureValue
|
||||
* @param block
|
||||
*/
|
||||
public SignatureValue(Block block) throws VlIntException {
|
||||
public SignatureValue(Block block) throws ComponentException {
|
||||
this.buildSignatureValueByBlock(block);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class SignatureValue implements TlvComponentBase, IEncodingAble {
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
public boolean buildSignatureValueByBlock(Block block) throws VlIntException {
|
||||
public boolean buildSignatureValueByBlock(Block block) throws ComponentException {
|
||||
return this.wireDecode(block);
|
||||
}
|
||||
|
||||
@@ -65,24 +65,37 @@ public class SignatureValue implements TlvComponentBase, 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("SignatureValue.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("SignatureValue.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvSignatureValue));
|
||||
try {
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvSignatureValue));
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("SignatureValue.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
@@ -97,18 +110,18 @@ public class SignatureValue implements TlvComponentBase, 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.TlvSignatureValue))){
|
||||
return false;
|
||||
}
|
||||
|
||||
int len= 0;
|
||||
// try {
|
||||
try {
|
||||
len = block.getLength().getVlIntValue2Int();
|
||||
// } catch (VlIntException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
} catch (VlIntException e) {
|
||||
throw new ComponentException("SignatureValue.wireDecode: "+e.getMessage());
|
||||
}
|
||||
this.value=new byte[len];
|
||||
System.arraycopy(block.getValue(),0,this.value,0,len);
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user