mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
error handle to all: VlIntException
This commit is contained in:
1 parent
96650c8f42
commit
30dd00ffb4
5 files changed
+21
-20
No files matched your search
@@ -147,7 +147,7 @@ public class SignatureField implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
// 检查 TYPE 是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvSignatureField))){
|
||||
return false;
|
||||
|
||||
@@ -38,7 +38,7 @@ public class SignatureInfo implements TlvComponentBase, IEncodingAble {
|
||||
* 根据 TLV Block 创建一个 SignatureInfo
|
||||
* @param block
|
||||
*/
|
||||
public SignatureInfo(Block block){
|
||||
public SignatureInfo(Block block) throws VlIntException {
|
||||
this.buildSignatureInfoByBlock(block);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class SignatureInfo implements TlvComponentBase, IEncodingAble {
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
public boolean buildSignatureInfoByBlock(Block block){
|
||||
public boolean buildSignatureInfoByBlock(Block block) throws VlIntException {
|
||||
return this.wireDecode(block);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class SignatureInfo implements TlvComponentBase, IEncodingAble {
|
||||
// 编码 TLV-TYPE
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvSignatureInfo));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
@@ -140,7 +140,7 @@ public class SignatureInfo implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
// 检查 Type 是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvSignatureInfo))){
|
||||
return false;
|
||||
|
||||
@@ -37,7 +37,7 @@ public class MINPacket implements IEncodingAble {
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
if(!this.isPacketValid()){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
int totalLength=0;
|
||||
|
||||
@@ -46,42 +46,42 @@ public class MINPacket implements IEncodingAble {
|
||||
// 可变区
|
||||
int tmplen=this.mutableField.wireEncode(encoder);
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 只读区
|
||||
tmplen=this.readOnlyField.wireEncode(encoder);
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 签名区
|
||||
tmplen=this.signatureField.wireEncode(encoder);
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 标识区
|
||||
tmplen=this.identifierField.wireEncode(encoder);
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码包 TLV-LENGTH
|
||||
tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码包 TLV-TYPE
|
||||
tmplen=encoder.prependVarNumber(this.packetType);
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
@@ -98,7 +98,7 @@ public class MINPacket implements IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
// 首先判断包是否有效
|
||||
if(!block.isValid()){
|
||||
return false;
|
||||
|
||||
@@ -16,7 +16,7 @@ import static org.junit.Assert.*;
|
||||
public class BlockTest {
|
||||
|
||||
@Test
|
||||
public void TestCreateBlockByTypeLengthBuffer() throws VlIntException {
|
||||
public void TestCreateBlockByTypeLengthBuffer() throws VlIntException, EncoderException {
|
||||
byte[] buf = new byte[10000];
|
||||
Block block = Block.createBlockByTypeLengthBuffer(new VlInt(241), new VlInt(8000),ByteHelper.getLenBytes(buf, new VlInt(0),8000),true);
|
||||
//测试type与size
|
||||
@@ -42,7 +42,7 @@ public class BlockTest {
|
||||
|
||||
//error:block.Size().size()错误。
|
||||
@Test
|
||||
public void TestCreateBlockByBuffer() throws VlIntException {
|
||||
public void TestCreateBlockByBuffer() throws VlIntException, EncoderException {
|
||||
byte[] buf = new byte[10000];
|
||||
buf[0] = (byte)212;
|
||||
buf[1] = (byte)241;
|
||||
@@ -59,7 +59,7 @@ public class BlockTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestBuildByBlock() throws VlIntException {
|
||||
public void TestBuildByBlock() throws VlIntException, EncoderException {
|
||||
//Block构造方法测试
|
||||
byte[] buf = new byte[10000];
|
||||
Block block1 = Block.createBlockByTypeLengthBuffer(new VlInt(241), new VlInt(8000),ByteHelper.getLenBytes(buf, new VlInt(0),8000),true);
|
||||
@@ -85,7 +85,7 @@ public class BlockTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestBuildByTypeLengthBuffer() throws VlIntException {
|
||||
public void TestBuildByTypeLengthBuffer() throws VlIntException, EncoderException {
|
||||
//Block构造方法测试
|
||||
byte[] buf = new byte[10000];
|
||||
Block block = new Block(new VlInt(241),new VlInt(8000),ByteHelper.getLenBytes(buf,new VlInt(0),8000),true);
|
||||
@@ -112,7 +112,7 @@ public class BlockTest {
|
||||
//error
|
||||
//TODO 错误处理
|
||||
@Test
|
||||
public void TestParseSubElements(){
|
||||
public void TestParseSubElements() throws EncoderException {
|
||||
byte[] buf = new byte[10000];
|
||||
for (int i = 0; i < 240; i++) {
|
||||
buf[i*8] = (byte)(i+1);
|
||||
@@ -133,7 +133,7 @@ public class BlockTest {
|
||||
//error
|
||||
//TODO 没测完
|
||||
@Test
|
||||
public void TestSubElements(){
|
||||
public void TestSubElements() throws EncoderException {
|
||||
byte[] buf = new byte[10000];
|
||||
Block block = new Block();
|
||||
block.setType(new VlInt(7));
|
||||
|
||||
@@ -2,6 +2,7 @@ package others;
|
||||
|
||||
import component.CanBePrefix;
|
||||
import encoding.Block;
|
||||
import encoding.EncoderException;
|
||||
import encoding.SelfEncodingBase;
|
||||
|
||||
/*
|
||||
@@ -12,7 +13,7 @@ import encoding.SelfEncodingBase;
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class TestCallBack {
|
||||
public static void main(String[] args){
|
||||
public static void main(String[] args) throws EncoderException {
|
||||
CanBePrefix canBePrefix=new CanBePrefix();
|
||||
Block block=new SelfEncodingBase().selfWireEncode(canBePrefix);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user