mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
add test: MutableProtectFieldTest
This commit is contained in:
1 parent
83992bed6c
commit
03672a15dc
3 files changed
+241
-96
No files matched your search
@@ -12,59 +12,64 @@ import encoding.*;
|
||||
public class MutableProtectField implements TlvComponentBase, IEncodingAble {
|
||||
private ElementContainer blocks;
|
||||
|
||||
public MutableProtectField(){
|
||||
blocks=new ElementContainer();
|
||||
public MutableProtectField() {
|
||||
blocks = new ElementContainer();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一个Block
|
||||
*
|
||||
* @param block
|
||||
*/
|
||||
public void addBlock(Block block){
|
||||
public void addBlock(Block block) {
|
||||
blocks.addElement(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定位置的 Block
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Block getBlock(int index) throws ComponentException {
|
||||
try {
|
||||
return this.blocks.getBlock(index);
|
||||
} catch (BlockException e) {
|
||||
throw new ComponentException("MutableProtectField.getBlock: "+e.getMessage());
|
||||
throw new ComponentException("MutableProtectField.getBlock: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空所有的子 Block
|
||||
*/
|
||||
public void clearBlocks(){
|
||||
public void clearBlocks() {
|
||||
this.blocks.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的 Block
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ElementContainer getBlocks(){
|
||||
public ElementContainer getBlocks() {
|
||||
return this.blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取第一个指定TLV-TYPE的子 TLV Block
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Block getBlockByType(VlInt tlvType) throws ComponentException {
|
||||
try {
|
||||
return this.blocks.getBlockByType(tlvType);
|
||||
} catch (BlockException e) {
|
||||
throw new ComponentException("MutableProtectField.getBlockByType: "+e.getMessage());
|
||||
throw new ComponentException("MutableProtectField.getBlockByType: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 线速编码为一个 TLV
|
||||
*
|
||||
* @param encoder
|
||||
* @return
|
||||
*/
|
||||
@@ -72,75 +77,76 @@ public class MutableProtectField implements TlvComponentBase, IEncodingAble {
|
||||
public int wireEncode(Encoder encoder) throws ComponentException {
|
||||
try {
|
||||
|
||||
// 如果没有任何子 TLV,则可以去掉它
|
||||
if(this.blocks.length()==0){
|
||||
return -1;
|
||||
}
|
||||
|
||||
int totalLength=0;
|
||||
// 编码TLV-VALUE
|
||||
// 反向遍历,可以保证解码的时候正向输出
|
||||
for(int i=this.blocks.length()-1;i>=0;i++){
|
||||
int tmplen= 0;
|
||||
tmplen = encoder.prependBlock(this.blocks.getBlock(i));
|
||||
|
||||
if(tmplen<=0){
|
||||
// 如果没有任何子 TLV,则可以去掉它
|
||||
if (this.blocks.length() == 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
}
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
int tmplen= 0;
|
||||
try {
|
||||
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("MutableProtectField.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
int totalLength = 0;
|
||||
// 编码TLV-VALUE
|
||||
// 反向遍历,可以保证解码的时候正向输出
|
||||
for (int i = this.blocks.length() - 1; i >= 0; i--) {
|
||||
int tmplen = 0;
|
||||
tmplen = encoder.prependBlock(this.blocks.getBlock(i));
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
try {
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvReadOnlyField));
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("MutableProtectField.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
if (tmplen <= 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmplen;
|
||||
}
|
||||
|
||||
return totalLength;
|
||||
// 编码 TLV-LENGTH
|
||||
int tmplen = 0;
|
||||
try {
|
||||
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("MutableProtectField.wireEncode: " + e.getMessage());
|
||||
}
|
||||
if (tmplen <= 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
try {
|
||||
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvMutableProtectField));
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("MutableProtectField.wireEncode: " + e.getMessage());
|
||||
}
|
||||
if (tmplen <= 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmplen;
|
||||
|
||||
return totalLength;
|
||||
} catch (EncoderException | BlockException e) {
|
||||
throw new ComponentException("MutableProtectField.wireEncode: "+e.getMessage());
|
||||
throw new ComponentException("MutableProtectField.wireEncode: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 TLV Block 中解码出一个 ReadOnlyField
|
||||
*
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) throws ComponentException {
|
||||
// 检查 Type 是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvReadOnlyField))){
|
||||
if (!TLV.expectType(block.getType(), new VlInt(TLV.TlvMutableProtectField))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 解析子 TLV
|
||||
try {
|
||||
if(!block.parseSubElements()){
|
||||
if (!block.parseSubElements()) {
|
||||
return false;
|
||||
}
|
||||
} catch (BlockException e) {
|
||||
throw new ComponentException("MutableProtectField.wireDecode: "+e.getMessage());
|
||||
throw new ComponentException("MutableProtectField.wireDecode: " + e.getMessage());
|
||||
}
|
||||
|
||||
this.blocks=block.getSubElements();
|
||||
this.blocks = block.getSubElements();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -26,38 +26,38 @@ public class MutableDangerousFieldTest {
|
||||
|
||||
@Test
|
||||
public void TestMutableDangerousField_GetBlock() throws BlockException, ComponentException {
|
||||
MutableDangerousField mutableDangerousField=new MutableDangerousField();
|
||||
MutableDangerousField mutable=new MutableDangerousField();
|
||||
byte[] buf={(byte)55, (byte)6, (byte)0, (byte)0, (byte)110, (byte)50, (byte)24, (byte)66};
|
||||
Block block=new Block(buf,false);
|
||||
byte[] buf1={(byte)55,(byte)0};
|
||||
Block block1=new Block(buf1,false);
|
||||
mutableDangerousField.addBlock(block);
|
||||
mutableDangerousField.addBlock(block1);
|
||||
System.out.println("block: "+mutableDangerousField.getBlock(0).getType()+", "
|
||||
+mutableDangerousField.getBlock(0).getLength()+", "
|
||||
+ Arrays.toString(mutableDangerousField.getBlock(0).getValue()));
|
||||
System.out.println("block1: "+mutableDangerousField.getBlock(1).getType()+", "
|
||||
+mutableDangerousField.getBlock(1).getLength()+", "
|
||||
+ Arrays.toString(mutableDangerousField.getBlock(1).getValue()));
|
||||
mutable.addBlock(block);
|
||||
mutable.addBlock(block1);
|
||||
System.out.println("block: "+mutable.getBlock(0).getType()+", "
|
||||
+mutable.getBlock(0).getLength()+", "
|
||||
+ Arrays.toString(mutable.getBlock(0).getValue()));
|
||||
System.out.println("block1: "+mutable.getBlock(1).getType()+", "
|
||||
+mutable.getBlock(1).getLength()+", "
|
||||
+ Arrays.toString(mutable.getBlock(1).getValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestMutableDangerousField_ClearBlocks() throws ComponentException, BlockException {
|
||||
MutableDangerousField mutableDangerousField=new MutableDangerousField();
|
||||
MutableDangerousField mutable=new MutableDangerousField();
|
||||
byte[] buf={(byte)55, (byte)6, (byte)0, (byte)0, (byte)110, (byte)50, (byte)24, (byte)66};
|
||||
Block block=new Block(buf,false);
|
||||
byte[] buf1={(byte)55,(byte)0};
|
||||
Block block1=new Block(buf1,false);
|
||||
mutableDangerousField.addBlock(block);
|
||||
mutableDangerousField.addBlock(block1);
|
||||
System.out.println("block: "+mutableDangerousField.getBlock(0).getType()+", "
|
||||
+mutableDangerousField.getBlock(0).getLength()+", "
|
||||
+ Arrays.toString(mutableDangerousField.getBlock(0).getValue()));
|
||||
System.out.println("block1: "+mutableDangerousField.getBlock(1).getType()+", "
|
||||
+mutableDangerousField.getBlock(1).getLength()+", "
|
||||
+ Arrays.toString(mutableDangerousField.getBlock(1).getValue()));
|
||||
mutableDangerousField.clearBlocks();
|
||||
System.out.println(mutableDangerousField.getBlocks().length());
|
||||
mutable.addBlock(block);
|
||||
mutable.addBlock(block1);
|
||||
System.out.println("block: "+mutable.getBlock(0).getType()+", "
|
||||
+mutable.getBlock(0).getLength()+", "
|
||||
+ Arrays.toString(mutable.getBlock(0).getValue()));
|
||||
System.out.println("block1: "+mutable.getBlock(1).getType()+", "
|
||||
+mutable.getBlock(1).getLength()+", "
|
||||
+ Arrays.toString(mutable.getBlock(1).getValue()));
|
||||
mutable.clearBlocks();
|
||||
System.out.println(mutable.getBlocks().length());
|
||||
// System.out.println("block: "+mutableDangerousField.getBlock(0).getType()+", "
|
||||
// +mutableDangerousField.getBlock(0).getLength()+", "
|
||||
// + Arrays.toString(mutableDangerousField.getBlock(0).getValue()));
|
||||
@@ -65,67 +65,67 @@ public class MutableDangerousFieldTest {
|
||||
|
||||
@Test
|
||||
public void TestMutableDangerousField_getBlocks() throws ComponentException, BlockException {
|
||||
MutableDangerousField mutableDangerousField=new MutableDangerousField();
|
||||
MutableDangerousField mutable=new MutableDangerousField();
|
||||
byte[] buf={(byte)55, (byte)6, (byte)0, (byte)0, (byte)110, (byte)50, (byte)24, (byte)66};
|
||||
Block block=new Block(buf,false);
|
||||
byte[] buf1={(byte)55,(byte)0};
|
||||
Block block1=new Block(buf1,false);
|
||||
mutableDangerousField.addBlock(block);
|
||||
mutableDangerousField.addBlock(block1);
|
||||
System.out.println("block: "+mutableDangerousField.getBlock(0).getType()+", "
|
||||
+mutableDangerousField.getBlock(0).getLength()+", "
|
||||
+ Arrays.toString(mutableDangerousField.getBlock(0).getValue()));
|
||||
System.out.println("block1: "+mutableDangerousField.getBlock(1).getType()+", "
|
||||
+mutableDangerousField.getBlock(1).getLength()+", "
|
||||
+ Arrays.toString(mutableDangerousField.getBlock(1).getValue()));
|
||||
System.out.println(mutableDangerousField.getBlocks().length());
|
||||
System.out.println("block: "+mutableDangerousField.getBlocks().getBlock(0).getType()+", "
|
||||
+mutableDangerousField.getBlock(0).getLength()+", "
|
||||
+ Arrays.toString(mutableDangerousField.getBlocks().getBlock(0).getValue()));
|
||||
mutable.addBlock(block);
|
||||
mutable.addBlock(block1);
|
||||
System.out.println("block: "+mutable.getBlock(0).getType()+", "
|
||||
+mutable.getBlock(0).getLength()+", "
|
||||
+ Arrays.toString(mutable.getBlock(0).getValue()));
|
||||
System.out.println("block1: "+mutable.getBlock(1).getType()+", "
|
||||
+mutable.getBlock(1).getLength()+", "
|
||||
+ Arrays.toString(mutable.getBlock(1).getValue()));
|
||||
System.out.println(mutable.getBlocks().length());
|
||||
System.out.println("block: "+mutable.getBlocks().getBlock(0).getType()+", "
|
||||
+mutable.getBlock(0).getLength()+", "
|
||||
+ Arrays.toString(mutable.getBlocks().getBlock(0).getValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestMutableDangerousField_getBlockByType() throws ComponentException, BlockException {
|
||||
MutableDangerousField mutableDangerousField=new MutableDangerousField();
|
||||
MutableDangerousField mutable=new MutableDangerousField();
|
||||
byte[] buf={(byte)56, (byte)6, (byte)0, (byte)0, (byte)110, (byte)50, (byte)24, (byte)66};
|
||||
Block block=new Block(buf,false);
|
||||
byte[] buf1={(byte)55,(byte)0};
|
||||
Block block1=new Block(buf1,false);
|
||||
mutableDangerousField.addBlock(block);
|
||||
mutableDangerousField.addBlock(block1);
|
||||
System.out.println("block: "+mutableDangerousField.getBlockByType(new VlInt(55)).getType()+", "
|
||||
+mutableDangerousField.getBlockByType(new VlInt(55)).getLength()+", "
|
||||
+ Arrays.toString(mutableDangerousField.getBlockByType(new VlInt(55)).getValue()));
|
||||
mutable.addBlock(block);
|
||||
mutable.addBlock(block1);
|
||||
System.out.println("block: "+mutable.getBlockByType(new VlInt(55)).getType()+", "
|
||||
+mutable.getBlockByType(new VlInt(55)).getLength()+", "
|
||||
+ Arrays.toString(mutable.getBlockByType(new VlInt(55)).getValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestMutableDangerousField_WireEncode() throws EncoderException, ComponentException, BlockException {
|
||||
MutableDangerousField mutableDangerousField=new MutableDangerousField();
|
||||
MutableDangerousField mutable=new MutableDangerousField();
|
||||
byte[] buf={(byte)56, (byte)6, (byte)0, (byte)0, (byte)110, (byte)50, (byte)24, (byte)66};
|
||||
Block block=new Block(buf,false);
|
||||
byte[] buf1={(byte)55,(byte)0};
|
||||
Block block1=new Block(buf1,false);
|
||||
mutableDangerousField.addBlock(block);
|
||||
mutableDangerousField.addBlock(block1);
|
||||
mutable.addBlock(block);
|
||||
mutable.addBlock(block1);
|
||||
Encoder encoder=new Encoder();
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
mutableDangerousField.wireEncode(encoder);
|
||||
mutable.wireEncode(encoder);
|
||||
byte[] bufget=encoder.getBuffer();
|
||||
System.out.println(Arrays.toString(bufget));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestMutableDangerousField_WireDecode()throws EncoderException, ComponentException, BlockException {
|
||||
MutableDangerousField mutableDangerousField=new MutableDangerousField();
|
||||
MutableDangerousField mutable=new MutableDangerousField();
|
||||
byte[] buf={(byte)56, (byte)6, (byte)0, (byte)0, (byte)110, (byte)50, (byte)24, (byte)66};
|
||||
Block block=new Block(buf,false);
|
||||
byte[] buf1={(byte)55,(byte)0};
|
||||
Block block1=new Block(buf1,false);
|
||||
mutableDangerousField.addBlock(block);
|
||||
mutableDangerousField.addBlock(block1);
|
||||
mutable.addBlock(block);
|
||||
mutable.addBlock(block1);
|
||||
Encoder encoder=new Encoder();
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
mutableDangerousField.wireEncode(encoder);
|
||||
mutable.wireEncode(encoder);
|
||||
byte[] bufget=encoder.getBuffer();
|
||||
Block newBlock=new Block(bufget,false);
|
||||
System.out.println(Arrays.toString(bufget));
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
package component;
|
||||
|
||||
import encoding.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description:
|
||||
* @Version: 1.0.0
|
||||
* @Date: 21:07 2021/3/25
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class MutableProtectFieldTest {
|
||||
@Test
|
||||
public void TestMutableProtectField_AddBlock() throws BlockException, ComponentException {
|
||||
MutableProtectField mutableProtectField=new MutableProtectField();
|
||||
byte[] buf={(byte)55, (byte)6, (byte)0, (byte)0, (byte)110, (byte)50, (byte)24, (byte)66};
|
||||
Block block=new Block(buf,false);
|
||||
mutableProtectField.addBlock(block);
|
||||
System.out.println("block: "+mutableProtectField.getBlock(0).getType()+", "
|
||||
+mutableProtectField.getBlock(0).getLength()+", "
|
||||
+ Arrays.toString(mutableProtectField.getBlock(0).getValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestMutableProtectField_GetBlock() throws BlockException, ComponentException {
|
||||
MutableProtectField mutable=new MutableProtectField();
|
||||
byte[] buf={(byte)55, (byte)6, (byte)0, (byte)0, (byte)110, (byte)50, (byte)24, (byte)66};
|
||||
Block block=new Block(buf,false);
|
||||
byte[] buf1={(byte)55,(byte)0};
|
||||
Block block1=new Block(buf1,false);
|
||||
mutable.addBlock(block);
|
||||
mutable.addBlock(block1);
|
||||
System.out.println("block: "+mutable.getBlock(0).getType()+", "
|
||||
+mutable.getBlock(0).getLength()+", "
|
||||
+ Arrays.toString(mutable.getBlock(0).getValue()));
|
||||
System.out.println("block1: "+mutable.getBlock(1).getType()+", "
|
||||
+mutable.getBlock(1).getLength()+", "
|
||||
+ Arrays.toString(mutable.getBlock(1).getValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestMutableProtectField_ClearBlocks() throws ComponentException, BlockException {
|
||||
MutableProtectField mutable=new MutableProtectField();
|
||||
byte[] buf={(byte)55, (byte)6, (byte)0, (byte)0, (byte)110, (byte)50, (byte)24, (byte)66};
|
||||
Block block=new Block(buf,false);
|
||||
byte[] buf1={(byte)55,(byte)0};
|
||||
Block block1=new Block(buf1,false);
|
||||
mutable.addBlock(block);
|
||||
mutable.addBlock(block1);
|
||||
System.out.println("block: "+mutable.getBlock(0).getType()+", "
|
||||
+mutable.getBlock(0).getLength()+", "
|
||||
+ Arrays.toString(mutable.getBlock(0).getValue()));
|
||||
System.out.println("block1: "+mutable.getBlock(1).getType()+", "
|
||||
+mutable.getBlock(1).getLength()+", "
|
||||
+ Arrays.toString(mutable.getBlock(1).getValue()));
|
||||
mutable.clearBlocks();
|
||||
System.out.println(mutable.getBlocks().length());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestMutableProtectField_getBlocks() throws ComponentException, BlockException {
|
||||
MutableProtectField mutable=new MutableProtectField();
|
||||
byte[] buf={(byte)55, (byte)6, (byte)0, (byte)0, (byte)110, (byte)50, (byte)24, (byte)66};
|
||||
Block block=new Block(buf,false);
|
||||
byte[] buf1={(byte)55,(byte)0};
|
||||
Block block1=new Block(buf1,false);
|
||||
mutable.addBlock(block);
|
||||
mutable.addBlock(block1);
|
||||
System.out.println("block: "+mutable.getBlock(0).getType()+", "
|
||||
+mutable.getBlock(0).getLength()+", "
|
||||
+ Arrays.toString(mutable.getBlock(0).getValue()));
|
||||
System.out.println("block1: "+mutable.getBlock(1).getType()+", "
|
||||
+mutable.getBlock(1).getLength()+", "
|
||||
+ Arrays.toString(mutable.getBlock(1).getValue()));
|
||||
System.out.println(mutable.getBlocks().length());
|
||||
System.out.println("block: "+mutable.getBlocks().getBlock(0).getType()+", "
|
||||
+mutable.getBlock(0).getLength()+", "
|
||||
+ Arrays.toString(mutable.getBlocks().getBlock(0).getValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestMutableProtectField_getBlockByType() throws ComponentException, BlockException {
|
||||
MutableProtectField mutable=new MutableProtectField();
|
||||
byte[] buf={(byte)56, (byte)6, (byte)0, (byte)0, (byte)110, (byte)50, (byte)24, (byte)66};
|
||||
Block block=new Block(buf,false);
|
||||
byte[] buf1={(byte)55,(byte)0};
|
||||
Block block1=new Block(buf1,false);
|
||||
mutable.addBlock(block);
|
||||
mutable.addBlock(block1);
|
||||
System.out.println("block: "+mutable.getBlockByType(new VlInt(55)).getType()+", "
|
||||
+mutable.getBlockByType(new VlInt(55)).getLength()+", "
|
||||
+ Arrays.toString(mutable.getBlockByType(new VlInt(55)).getValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestMutableProtectField_WireEncode() throws EncoderException, ComponentException, BlockException {
|
||||
MutableProtectField mutable=new MutableProtectField();
|
||||
byte[] buf={(byte)56, (byte)6, (byte)0, (byte)0, (byte)110, (byte)50, (byte)24, (byte)66};
|
||||
Block block=new Block(buf,false);
|
||||
byte[] buf1={(byte)55,(byte)0};
|
||||
Block block1=new Block(buf1,false);
|
||||
mutable.addBlock(block);
|
||||
mutable.addBlock(block1);
|
||||
Encoder encoder=new Encoder();
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
mutable.wireEncode(encoder);
|
||||
byte[] bufget=encoder.getBuffer();
|
||||
System.out.println(Arrays.toString(bufget));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestMutableProtectField_WireDecode()throws EncoderException, ComponentException, BlockException {
|
||||
MutableProtectField mutable=new MutableProtectField();
|
||||
byte[] buf={(byte)56, (byte)6, (byte)0, (byte)0, (byte)110, (byte)50, (byte)24, (byte)66};
|
||||
Block block=new Block(buf,false);
|
||||
byte[] buf1={(byte)55,(byte)0};
|
||||
Block block1=new Block(buf1,false);
|
||||
mutable.addBlock(block);
|
||||
mutable.addBlock(block1);
|
||||
Encoder encoder=new Encoder();
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
mutable.wireEncode(encoder);
|
||||
byte[] bufget=encoder.getBuffer();
|
||||
Block newBlock=new Block(bufget,false);
|
||||
System.out.println(Arrays.toString(bufget));
|
||||
MutableProtectField mutable1=new MutableProtectField();
|
||||
mutable1.wireDecode(newBlock);
|
||||
System.out.println(mutable1.getBlocks().length());
|
||||
System.out.println("block: "+mutable1.getBlock(0).getType()+", "
|
||||
+mutable1.getBlock(0).getLength()+", "
|
||||
+ Arrays.toString(mutable1.getBlock(0).getValue()));
|
||||
System.out.println("block1: "+mutable1.getBlock(1).getType()+", "
|
||||
+mutable1.getBlock(1).getLength()+", "
|
||||
+ Arrays.toString(mutable1.getBlock(1).getValue()));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user