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