mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
add test: ReadOnlyFieldTest
This commit is contained in:
1 parent
0a7ccc95a3
commit
8a2da10583
19 files changed
+1251
-966
No files matched your search
@@ -12,6 +12,10 @@ import encoding.*;
|
||||
public class MutableDangerousField implements TlvComponentBase, IEncodingAble {
|
||||
private ElementContainer blocks;
|
||||
|
||||
public MutableDangerousField(){
|
||||
blocks=new ElementContainer();
|
||||
}
|
||||
|
||||
/**
|
||||
* 往可变非受保护区添加一个Block
|
||||
* @param block
|
||||
@@ -24,8 +28,12 @@ public class MutableDangerousField implements TlvComponentBase, IEncodingAble {
|
||||
* 获取可变非受保护区指定位置的 Block
|
||||
* @return
|
||||
*/
|
||||
public Block getBlock(int index){
|
||||
return this.blocks.getBlock(index);
|
||||
public Block getBlock(int index) throws ComponentException {
|
||||
try {
|
||||
return this.blocks.getBlock(index);
|
||||
} catch (BlockException e) {
|
||||
throw new ComponentException("MutableDangerousField.getBlock: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,8 +55,12 @@ public class MutableDangerousField implements TlvComponentBase, IEncodingAble {
|
||||
* 获取可变非受保护区中,第一个指定TLV-TYPE的子 TLV Block
|
||||
* @return
|
||||
*/
|
||||
public Block getBlockByType(VlInt tlvType){
|
||||
return this.blocks.getElement(tlvType);
|
||||
public Block getBlockByType(VlInt tlvType) throws ComponentException {
|
||||
try {
|
||||
return this.blocks.getElement(tlvType);
|
||||
} catch (BlockException e) {
|
||||
throw new ComponentException("MutableDangerousField.getBlockByType: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,6 +70,7 @@ public class MutableDangerousField implements TlvComponentBase, IEncodingAble {
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) throws ComponentException {
|
||||
try{
|
||||
// 如果可变非受保护区没有任何子 TLV,则可以去掉可变非受保护区 TLV
|
||||
if(this.blocks.length()==0){
|
||||
return -1;
|
||||
@@ -68,11 +81,7 @@ public class MutableDangerousField implements TlvComponentBase, IEncodingAble {
|
||||
// 反向遍历,可以保证解码的时候正向输出
|
||||
for(int i=this.blocks.length()-1;i>=0;i++){
|
||||
int tmplen= 0;
|
||||
try {
|
||||
tmplen = encoder.prependBlock(this.blocks.getBlock(i));
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("MutableDangerousField.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
@@ -81,11 +90,7 @@ public class MutableDangerousField implements TlvComponentBase, IEncodingAble {
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
int tmplen= 0;
|
||||
try {
|
||||
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("MutableDangerousField.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
@@ -103,6 +108,9 @@ public class MutableDangerousField implements TlvComponentBase, IEncodingAble {
|
||||
totalLength+=tmplen;
|
||||
|
||||
return totalLength;
|
||||
} catch (EncoderException | BlockException e) {
|
||||
throw new ComponentException("MutableDangerousField.wireEncode: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user