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
@@ -1,5 +1,6 @@
|
||||
package packet;
|
||||
|
||||
import component.ComponentException;
|
||||
import component.IdentifierWrapper;
|
||||
import component.Payload;
|
||||
import component.TTL;
|
||||
@@ -51,13 +52,18 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean fillDataToFields() throws EncoderException, BlockException {
|
||||
public boolean fillDataToFields() throws PacketException {
|
||||
// 可变区 => 受保护区(无)
|
||||
|
||||
// 填充可变区 => 非受保护区
|
||||
// 首先清除所有的Block
|
||||
this.minPacket.mutableField.mutableDangerousField.clearBlocks();
|
||||
Block block=new SelfEncodingBase().selfWireEncode(this.ttl);
|
||||
Block block= null;
|
||||
try {
|
||||
block = new SelfEncodingBase().selfWireEncode(this.ttl);
|
||||
} catch (EncoderException | BlockException e) {
|
||||
throw new PacketException("CPacket.fillDataToFields: "+e.getMessage());
|
||||
}
|
||||
if(block==null){
|
||||
return false;
|
||||
}
|
||||
@@ -66,7 +72,11 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
// 填充只读区
|
||||
// 首先清除所有的Block
|
||||
this.minPacket.readOnlyField.clearBlocks();
|
||||
block=new SelfEncodingBase().selfWireEncode(this.payload);
|
||||
try {
|
||||
block=new SelfEncodingBase().selfWireEncode(this.payload);
|
||||
} catch (EncoderException | BlockException e) {
|
||||
throw new PacketException("CPacket.fillDataToFields: "+e.getMessage());
|
||||
}
|
||||
if(block==null){
|
||||
return false;
|
||||
}
|
||||
@@ -90,7 +100,7 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean extraDataFromFields() throws VlIntException {
|
||||
public boolean extraDataFromFields() throws PacketException {
|
||||
// 提取 Payload
|
||||
Block payloadBlock=this.minPacket.readOnlyField.getBlockByType(new VlInt(TLV.TlvPayload));
|
||||
if(payloadBlock==null){
|
||||
@@ -105,8 +115,12 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
if(ttlBlock==null){
|
||||
return false;
|
||||
}
|
||||
if(this.ttl.wireDecode(ttlBlock)){
|
||||
return false;
|
||||
try {
|
||||
if(this.ttl.wireDecode(ttlBlock)){
|
||||
return false;
|
||||
}
|
||||
} catch (ComponentException e) {
|
||||
throw new PacketException("CPacket.extraDataFromFields: "+e.getMessage());
|
||||
}
|
||||
|
||||
// 提取标识
|
||||
@@ -128,7 +142,7 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) throws EncoderException, BlockException {
|
||||
public int wireEncode(Encoder encoder) throws PacketException {
|
||||
// 首先将属性填充到分区当中
|
||||
if(!this.fillDataToFields()){
|
||||
return 0;
|
||||
@@ -137,7 +151,11 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
// 指定包类型
|
||||
this.minPacket.packetType=new VlInt(TLV.TlvPacketMINCommon);
|
||||
|
||||
return this.minPacket.wireEncode(encoder);
|
||||
try {
|
||||
return this.minPacket.wireEncode(encoder);
|
||||
} catch (EncoderException e) {
|
||||
throw new PacketException("CPacket.wireEncode: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,9 +164,13 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
if(!this.minPacket.wireDecode(block)){
|
||||
return false;
|
||||
public boolean wireDecode(Block block) throws PacketException {
|
||||
try {
|
||||
if(!this.minPacket.wireDecode(block)){
|
||||
return false;
|
||||
}
|
||||
} catch (VlIntException e) {
|
||||
throw new PacketException("CPacket.wireDecode: "+e.getMessage());
|
||||
}
|
||||
return this.extraDataFromFields();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user