mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
finish encoding: SelfEncodingBase
This commit is contained in:
1 parent
0a945ada8e
commit
8bd3547a70
6 files changed
+209
-8
No files matched your search
@@ -1,5 +1,10 @@
|
||||
package packet;
|
||||
|
||||
import component.IdentifierWrapper;
|
||||
import component.Payload;
|
||||
import component.TTL;
|
||||
import encoding.*;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description:
|
||||
@@ -27,6 +32,79 @@ package packet;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
public class CPacket {
|
||||
public class CPacket implements InteractWithField, IEncodingAble {
|
||||
private MINPacket minPacket;
|
||||
private TTL ttl;
|
||||
private Payload payload;
|
||||
private String flatIdentifier; // 推式包拥有一个扁平的标识
|
||||
|
||||
public CPacket(){
|
||||
minPacket=new MINPacket();
|
||||
ttl=new TTL();
|
||||
payload=new Payload();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 CPacket 的各项属性填充到 MINPacket 中定义的对应分区当中
|
||||
* @Description:
|
||||
* // 1. 主要填充标识区、只读区和可变区
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean fillDataToFields() {
|
||||
// 可变区 => 受保护区(无)
|
||||
|
||||
// 填充可变区 => 非受保护区
|
||||
// 首先清除所有的Block
|
||||
this.minPacket.mutableField.mutableDangerousField.clearBlocks();
|
||||
// Block block
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 MINPacket 的分区当中提取出 CPacket 的各项属性
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean extraDataFromFields() {
|
||||
// 提取 Payload
|
||||
Block payloadBlock=this.minPacket.readOnlyField.getBlockByType(new VlInt(TLV.TlvPayload));
|
||||
if(payloadBlock==null){
|
||||
return false;
|
||||
}
|
||||
if(this.payload.wireDecode(payloadBlock)){
|
||||
return false;
|
||||
}
|
||||
|
||||
// 提取 TTL
|
||||
Block ttlBlock=this.minPacket.mutableField.mutableDangerousField.getBlockByType(new VlInt(TLV.TlvTTL));
|
||||
if(ttlBlock==null){
|
||||
return false;
|
||||
}
|
||||
if(this.ttl.wireDecode(ttlBlock)){
|
||||
return false;
|
||||
}
|
||||
|
||||
// 提取标识
|
||||
IdentifierWrapper commonIdentifier=this.minPacket.identifierField.getIdentifierByType(new VlInt(TLV.TlvIdentifierCommon));
|
||||
if(commonIdentifier==null){
|
||||
return false;
|
||||
}
|
||||
String identifierString=commonIdentifier.toUri();
|
||||
if((identifierString.length()>0)&&(identifierString.startsWith("/"))){
|
||||
this.flatIdentifier=identifierString.substring(1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user