mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-06-18 00:10:25 +08:00
change identifier.toString() && add componnet:NoCache
This commit is contained in:
@@ -22,6 +22,14 @@ public class ControlParameterCommonString implements IEncodingAble {
|
||||
this.commonString=new CommonString(new VlInt(TLV.TlvManagementCommonString),str);
|
||||
}
|
||||
|
||||
public String getCommonString() {
|
||||
return this.commonString.getValue();
|
||||
}
|
||||
|
||||
public void setCommonString(String str) {
|
||||
this.commonString.setValue(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* WireEncode 将 ControlParameterCommonString 线速编码为一个TLV
|
||||
* @param encoder
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package component;
|
||||
|
||||
import encoding.*;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description: ControlParameterPasswd 表示一个控制命令参数 Passwd
|
||||
* @Version: 1.0.0
|
||||
* @Date: 15:18 2021/5/25
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class ControlParameterPasswd implements IEncodingAble {
|
||||
public CommonString commonString=new CommonString();
|
||||
|
||||
public ControlParameterPasswd(){
|
||||
this.commonString.setTlvType(new VlInt(TLV.TlvManagementPasswd));
|
||||
}
|
||||
|
||||
public ControlParameterPasswd(String passwd){
|
||||
this.commonString=new CommonString(new VlInt(TLV.TlvManagementPasswd),passwd);
|
||||
}
|
||||
|
||||
public String getPasswd() {
|
||||
return this.commonString.getValue();
|
||||
}
|
||||
|
||||
public void setPasswd(String passwd) {
|
||||
this.commonString.setValue(passwd);
|
||||
}
|
||||
|
||||
/**
|
||||
* WireEncode 将 ControlParameterPasswd 线速编码为一个TLV
|
||||
* @param encoder
|
||||
* @return
|
||||
* @throws ComponentException
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) throws ComponentException {
|
||||
try {
|
||||
this.commonString.setTlvType(new VlInt(TLV.TlvManagementPasswd));
|
||||
return this.commonString.wireEncode(encoder);
|
||||
} catch (ComponentException e) {
|
||||
throw new ComponentException("ControlParameterPasswd.wireEncode: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* WireDecode 从 TLV Block 中解码出一个 ControlParameterPasswd
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block){
|
||||
// 检查 Type 是否正确
|
||||
if (!TLV.expectType(block.getType(), new VlInt(TLV.TlvManagementPasswd))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.commonString.wireDecode(block);
|
||||
}
|
||||
}
|
||||
@@ -216,6 +216,18 @@ public class Identifier implements TlvComponentBase, IEncodingAble {
|
||||
return res;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
try {
|
||||
String res = "";
|
||||
for (int i = 0; i < components.length(); i++) {
|
||||
res += ("/" + components.getElement(i).toString());
|
||||
}
|
||||
return res;
|
||||
} catch (ComponentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否名称组件数量为空
|
||||
*
|
||||
|
||||
@@ -354,4 +354,19 @@ public class IdentifierComponent implements TlvComponentBase, IEncodingAble {
|
||||
return Long.valueOf(this.intValue).toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* marker加上标识中的内容转换成的字符串数据
|
||||
* @return
|
||||
*/
|
||||
public String toString() {
|
||||
if (isString()) {
|
||||
return this.marker+StringHelper.escape(this.stringValue);
|
||||
} else if(isByteArray()){
|
||||
return this.marker+StringHelper.escape(new String(this.byteArrayValue));
|
||||
}else{
|
||||
// todo: 需要对long类型按照指定编码规则编码成字符串
|
||||
return this.marker+Long.valueOf(this.intValue).toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
package component;
|
||||
|
||||
import encoding.*;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description:
|
||||
* @Version: 1.0.0
|
||||
* @Date: 11:33 2021/3/9
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class NoCache implements TlvComponentBase,InitialAble, IEncodingAble {
|
||||
// 成员变量
|
||||
private boolean noCache;
|
||||
|
||||
public NoCache(){
|
||||
}
|
||||
|
||||
public NoCache(boolean noCache){
|
||||
this.setNoCache(noCache);
|
||||
}
|
||||
|
||||
// 函数
|
||||
public void setNoCache(boolean noCache){
|
||||
this.noCache = noCache;
|
||||
this.doInitial();
|
||||
}
|
||||
|
||||
public boolean getNoCache(){
|
||||
return this.noCache;
|
||||
}
|
||||
|
||||
// 接口实现-变量区
|
||||
private boolean initial=false;
|
||||
|
||||
// 接口实现-方法区
|
||||
@Override
|
||||
public void doInitial() {
|
||||
initial=true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitial() {
|
||||
return initial;
|
||||
}
|
||||
|
||||
/**
|
||||
* WireEncode 将 NoCache 线速编码为一个 TLV
|
||||
* @param encoder
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) throws ComponentException {
|
||||
try {
|
||||
// 这是一个存在性组件,所以如果值为false,则无需编码
|
||||
if (!this.noCache) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int totalLength = 0;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
int tmplen = encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if (tmplen < 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvCanBePrefix));
|
||||
if (tmplen < 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmplen;
|
||||
|
||||
return totalLength;
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("CanBePrefix.wireEncode: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* WireDecode 从 TLV Block 中解码出一个 NoCache
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
// 检查 Type 是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvCanBePrefix))){
|
||||
return false;
|
||||
}
|
||||
|
||||
// 这是一个存在性组件,所以存在则为 true
|
||||
this.setNoCache(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user