mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
error handle to all: EncoderException
This commit is contained in:
1 parent
5fc080ca6c
commit
8cf6ed24c9
34 files changed
+700
-233
No files matched your search
@@ -0,0 +1,10 @@
|
||||
# Exception
|
||||
当异常没有那么严重,属于程序自己可以处理的情形时,应当把这个异常抛出,然后交由上层方法去捕获并处理该异常。
|
||||
如果需要根据返回值去判断是否发生异常,那么,
|
||||
1. 当这个返回值正常情况下只能是正整数时,异常发生则返回-1;
|
||||
2. 当这个返回值正常情况下只能是正整数或0时,异常发生则返回-1;
|
||||
|
||||
# Error
|
||||
当异常属于不可处理的错误,应当直接抛出,提醒用户该错误发生的位置。
|
||||
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
# MIR Management
|
||||
|
||||
MIR管理通信协议允许用户、工具和控制平面程序检索,监视和更改MIR的状态。
|
||||
|
||||
## 1. MIR管理协议
|
||||
|
||||
### 1.1 基本机制
|
||||
|
||||
MIR通信管理协议使用管理通信包(Interest-Data exchange)来进行通信,管理通信包的顶层TLV的TYPE值为1。
|
||||
|
||||
- **Status Dataset** (状态数据集)
|
||||
|
||||
> https://redmine.named-data.net/projects/nfd/wiki/StatusDataset
|
||||
|
||||
状态数据集定义了一个实体集合的状态信息如何作为管理数据包(Management Data)进行编码、分片和发布。这个机制搭配兴趣包数据包交换(Interest-Data exchange)的通信方式可以很方便的对MIR中的各种状态信息进行检索。
|
||||
|
||||
- **Notification Stream**(通知流)
|
||||
|
||||
MIR管理通信协议要求实现一个基于事件订阅的通知机制,一旦MIR的相关状态发生改变,可以通过该机制通知对应的管理模块。这个机制可以很有效的对MIR的状态进行监视。
|
||||
|
||||
- **Control Command**(控制命令)
|
||||
|
||||
控制命令定义了一系列可以更改MIR状态的命令的请求和回复格式,*以及如何对这些命令进行签名和认证*。这个机制对于更改MIR的状态很有用。
|
||||
|
||||
### 1.2 模块
|
||||
|
||||
- **LogicFace Management**(逻辑接口管理模块)
|
||||
- 创建和销毁逻辑接口控制命令;
|
||||
- 一个数据集(dataset)用于发布 LogicFace 状态和计数器;
|
||||
- 一个通知流(Notification Stream),用于通知逻辑接口的创建和销毁事件
|
||||
- **FIB Management**(转发表管理模块)
|
||||
- 插入、更新和删除FIB条目的控制命令;
|
||||
- 一个数据集(dataset)用于发布FIB表的条目信息;
|
||||
|
||||
### 1.3 管理请求包的基本格式
|
||||
|
||||
```
|
||||
CommandInterest = 1 TLV-LENGTH
|
||||
{ InterestIdentifier } => 标识区
|
||||
{ Signature } => 签名区
|
||||
```
|
||||
|
||||
- **用于本地管理**:
|
||||
|
||||
```
|
||||
/localhost/mir/<模块名称>/<命令>/<参数>/[版本号]/[分片号]
|
||||
```
|
||||
|
||||
- 模块名称:每个管理模块会有一个唯一的模块名称,例如:`fib-mgmt`
|
||||
|
||||
- 命令:表示要在对应模块执行的动作,例如:`add`、`list`
|
||||
|
||||
- 参数:由一个 `ControlParameters` TLV 编码而成,其中包含一系列子 TLV,每个子TLV表示一个请求的参数字段(Field),例如:
|
||||
|
||||
```
|
||||
ControlParameters = CONTROL-PARAMETERS-TYPE TLV-LENGTH
|
||||
[LocalFaceUri]
|
||||
[RemoteFaceUri]
|
||||
```
|
||||
|
||||
- 版本号:数据集在每次版本更迭时,会将发布的数据状态的版本号加1,可以凭借版本号获取最新的状态信息
|
||||
|
||||
- 分片号:数据集通常无法用一个Data包装下,需要进行分片发布,分片号指定要拉取的数据分片
|
||||
|
||||
- **用于单跳接入**(用于使用TCP LogicFace等接入MIR的场景)
|
||||
|
||||
```
|
||||
/localhop/mir/<模块名称>/<命令>/<参数>/[版本号]/[分片号]
|
||||
```
|
||||
|
||||
### 1.4 管理回复包的基本格式
|
||||
|
||||
```
|
||||
CommandData = 1 TLV-LENGTH
|
||||
{ DataIdentifier } => 标识区
|
||||
{ Signature } => 签名区
|
||||
{ => 只读区
|
||||
<Payload>
|
||||
}
|
||||
```
|
||||
|
||||
回复数据放在管理回复包的 `Payload` 部分,格式为json格式,如果数据较多,需要分片进行传输
|
||||
|
||||
## 2. LogicFace Management
|
||||
|
||||
> 模块名称:`minlf-mgmt`
|
||||
|
||||
### 2.1 控制命令
|
||||
|
||||
- **`list`**
|
||||
|
||||
> list 命令用于显示逻辑接口的详细信息
|
||||
|
||||
```
|
||||
mirc lf list [remote <LFURI>] [local <LFURI>] [scheme <SCHEME>]
|
||||
```
|
||||
|
||||
- **`add`**
|
||||
|
||||
> add 命令用于添加一个逻辑接口
|
||||
|
||||
```
|
||||
mirc lf add remote <LFURI> [[persistency] <PERSISTENCY>] [local <LFURI>] [mtu <MTU>]
|
||||
```
|
||||
|
||||
- **`del`**
|
||||
|
||||
> del 命令用于删除一个逻辑接口
|
||||
|
||||
```
|
||||
mirc lf del <LFID|LFURI>
|
||||
```
|
||||
|
||||
- **`show`**
|
||||
|
||||
> show 命令用于展示指定ID的逻辑接口的信息
|
||||
|
||||
```
|
||||
mirc lf show <LFID>
|
||||
```
|
||||
|
||||
### 2.2 OPTIONS
|
||||
|
||||
- **LFID**
|
||||
|
||||
LfId 表示逻辑接口在MIR中的唯一数字标识
|
||||
|
||||
- **LFURI**
|
||||
|
||||
LfUri 表示本地或者远端的逻辑接口的地址,示例如下:
|
||||
|
||||
- `tcp://192.168.1.2:13899`
|
||||
- `udp://192.168.1.3:13899`
|
||||
- `ether://[08:00:27:01:01:01]`
|
||||
- `dev://eth0`
|
||||
- `unix:///var/run/mir.sock`
|
||||
|
||||
- **SCHEME**
|
||||
|
||||
Scheme 表示本地或者远端的接口地址所使用的Uri方案,示例如下:
|
||||
|
||||
- udp
|
||||
- tcp
|
||||
- unix
|
||||
- dev
|
||||
|
||||
- **PERSISTENCY**
|
||||
|
||||
Persistency 参数指定了逻辑接口的持久性,取值可以为 `persistent` (持久的)和 `permanent`(永久的)
|
||||
|
||||
- `persistent`:拥有 `persistent` 持久性的逻辑接口,在通信过程中发生套接字错误时,会自动关闭并销毁该逻辑接口;
|
||||
- `permanent`:拥有 `permanent` 持久性的逻辑接口,在通信过程中如果发生套接字错误是,逻辑接口不会直接销毁,会一直保留,并尝试重新建立套接字连接。
|
||||
|
||||
- **MTU**
|
||||
|
||||
Mtu 参数指定了逻辑接口的最大传输单元的大小。
|
||||
|
||||
## 3. FIB Management
|
||||
|
||||
> 模块名称:`fib-mgmt`
|
||||
|
||||
### 3.1 控制命令
|
||||
|
||||
- **`list`**
|
||||
|
||||
> list 命令用于展示 FIB 表的信息
|
||||
|
||||
`mirc fib list `
|
||||
|
||||
- **`add`**
|
||||
|
||||
- **`del`**
|
||||
@@ -0,0 +1,305 @@
|
||||
# MIN Packet Format
|
||||
|
||||
## 1. TLV
|
||||
|
||||
- 网络分组级别
|
||||
|
||||
0 ~ 49
|
||||
|
||||
| Type | TLV number | Description |
|
||||
| :-----------------: | :--------: | :-----------: |
|
||||
| PacketMINCommon | 0 | 通用MIN网络包 |
|
||||
| PacketMINManagement | 1 | MIN网络管理包 |
|
||||
| PacketMINIP | 2 | MIN网络IP包 |
|
||||
|
||||
- 网络包分区
|
||||
|
||||
50 ~ 99
|
||||
|
||||
| Type | TLV number | Description |
|
||||
| :------------------------: | :--------: | :----------------------: |
|
||||
| IdentifierField | 50 | 目的标识区 |
|
||||
| SignatureField | 51 | 数字签名区 |
|
||||
| ReadOnlyField | 52 | 只读数据区 |
|
||||
| VariableField | 53 | 可变数据区 |
|
||||
| VariableProtectField | 54 | 可变数据区中的受保护区 |
|
||||
| VariableDangerousField | 55 | 可变数据区中的非受保护区 |
|
||||
|
||||
- 标识分配
|
||||
|
||||
100 ~ 199
|
||||
|
||||
| Type | TLV number | Description |
|
||||
| ------------------------- | ---------- | ------------ |
|
||||
| IdentifierComponent | 100 | 标识名称组件 |
|
||||
| Identifier | 101 | 标识值 |
|
||||
| IdentifierCommon | 102 | 身份标识 |
|
||||
| IdentifierContentInterest | 103 | 内容兴趣标识 |
|
||||
| IdentifierContentData | 104 | 内容数据标识 |
|
||||
|
||||
- 其它TLV组件
|
||||
|
||||
200 ~ 500
|
||||
|
||||
| Type | TLV number | Description |
|
||||
| ---------------- | ---------- | -------------------------------------- |
|
||||
| SignatureValue | 200 | 签名值 |
|
||||
| SignatureInfo | 201 | 签名参数 |
|
||||
| SignatureType | 202 | 签名类型 |
|
||||
| TlvKeyLocator | 203 | 指示证书或公钥的位置 |
|
||||
| Payload | 204 | 网络包负载 |
|
||||
| CanBePrefix | 205 | 是否可以被较长的数据包前缀匹配 |
|
||||
| MustBeRefresh | 206 | 是否强制只拉取新鲜的数据 |
|
||||
| InterestLifeTime | 207 | 兴趣包生存期 |
|
||||
| Nonce | 208 | 随机数 |
|
||||
| HopLimit | 209 | 跳数限制 |
|
||||
| FreshnessPeriod | 210 | 数据包新鲜时间 |
|
||||
| CongestionMark | 211 | 拥塞标记 |
|
||||
| TTL | 212 | Time to live |
|
||||
| SliceNumber | 213 | 分片数量 |
|
||||
| SliceSize | 214 | 分片大小 |
|
||||
| LogicFaceId | 215 | 逻辑接口Id |
|
||||
| RemoteAddr | 216 | 远端地址 |
|
||||
| LocalAddr | 217 | 本地地址 |
|
||||
| Mtu | 218 | 最大传输单元 |
|
||||
| Ret | 219 | bool类型,成功或失败 |
|
||||
| Origin | 220 | |
|
||||
| Cost | 221 | 链路开销 |
|
||||
| Expires | 222 | LogicFace超时时间,-1为不超时(never) |
|
||||
|
||||
## 2. Identifier
|
||||
|
||||
```
|
||||
IdentifierComponent = 100 TLV-LENGTH
|
||||
<Marker>
|
||||
*OCTET
|
||||
Marker = OCTET
|
||||
|
||||
Identifier = 101 TLV-LENGTH
|
||||
*IdentifierComponent
|
||||
```
|
||||
|
||||
- `*OCTET`:字符串
|
||||
|
||||
- `Marker`:单个字节,用于区分不同类型的IdentifierComponent,分配如下
|
||||
|
||||
| Marker value | Description |
|
||||
| :----------: | :------------------------------------: |
|
||||
| 0x00 | 普通的UTF-8编码的字符串 |
|
||||
| 0x01 | 非负整数(可以用1、2、4、8个字节表示) |
|
||||
| 0x02 | 任意字节数组 |
|
||||
|
||||
### 2.1 CommonIdentifier
|
||||
|
||||
```
|
||||
CommonIdentifier = 102 TLV-LENGTH
|
||||
<Identifier>
|
||||
```
|
||||
|
||||
### 2.2 InterestIdentifier
|
||||
|
||||
```
|
||||
InterestIdentifier = 103 TLV-LENGTH
|
||||
<Identifier>
|
||||
```
|
||||
|
||||
### 2.3 DataIdentifier
|
||||
|
||||
```
|
||||
DataIdentifier = 104 TLV-LENGTH
|
||||
<Identifier>
|
||||
```
|
||||
|
||||
## 3. MIN Packet
|
||||
|
||||
### 3.1 CPacket
|
||||
|
||||
```
|
||||
CPacket = 0 TLV-LENGTH
|
||||
{ CommonIdentifier } => 标识区
|
||||
{ Signature } => 签名区
|
||||
{ => 只读区
|
||||
<Payload>
|
||||
}
|
||||
{ => 可变区
|
||||
{ => 受保护区
|
||||
"Empty"
|
||||
}
|
||||
{ => 非受保护区
|
||||
[TTL]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- `Payload`
|
||||
|
||||
```
|
||||
Payload = PAYLOAD-TYPE TLV-LENGTH *OCTET
|
||||
```
|
||||
|
||||
|
||||
### 3.2 Interest
|
||||
|
||||
```
|
||||
Interest = 0 TLV-LENGTH
|
||||
{ InterestIdentifier } => 标识区
|
||||
{ Signature } => 签名区
|
||||
{ => 只读区
|
||||
[CanBePrefix]
|
||||
[MustBeRefresh]
|
||||
[InterestLifeTime]
|
||||
[Nonce]
|
||||
[HopLimit]
|
||||
<Payload>
|
||||
}
|
||||
{ => 可变区
|
||||
{ => 受保护区
|
||||
[CongestionMark]
|
||||
}
|
||||
{ => 非受保护区
|
||||
"Empty"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- `CanBePrefix`
|
||||
|
||||
```
|
||||
CanBePrefix = 203
|
||||
TLV-LENGTH; == 0
|
||||
```
|
||||
|
||||
- `MustBeFresh`
|
||||
|
||||
```
|
||||
MustBeFresh = 204
|
||||
TLV-LENGTH; == 0
|
||||
```
|
||||
|
||||
- `InterestLifeTime`
|
||||
|
||||
```
|
||||
InterestLifeTime = 205 TLV-LENGTH NoNegativeInteger
|
||||
```
|
||||
|
||||
- `NonNegativeInteger` :非负整数
|
||||
|
||||
- `Nonce`
|
||||
|
||||
```
|
||||
Nonce = 206
|
||||
TLV-LENGTH; == 4
|
||||
4OCTET
|
||||
```
|
||||
|
||||
- `4OCTET`:四字节字符串
|
||||
|
||||
- `HopLimit`
|
||||
|
||||
```
|
||||
HopLimit = 207
|
||||
TLV-LENGTH; == 1
|
||||
OCTET
|
||||
```
|
||||
|
||||
- `OCTET`:1字节无符号整数
|
||||
|
||||
### 3.3 Data
|
||||
|
||||
```
|
||||
Data = 0 TLV-LENGTH
|
||||
{ DataIdentifier } => 标识区
|
||||
{ Signature } => 签名区
|
||||
{ => 只读区
|
||||
[FreshnessPeriod]
|
||||
<Payload>
|
||||
}
|
||||
{ => 可变区
|
||||
{ => 受保护区
|
||||
[CongestionMark]
|
||||
}
|
||||
{ => 非受保护区
|
||||
"Empty"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3.4 ManagementPacket
|
||||
|
||||
- Request
|
||||
|
||||
```
|
||||
ManagementRequestPacket = 1 TLV-LENGTH
|
||||
{ InterestIdentifier } => 标识区
|
||||
{ Signature } => 签名区
|
||||
```
|
||||
|
||||
- Response
|
||||
|
||||
```
|
||||
ManagementResponsePacket = 1 TLV-LENGTH
|
||||
{ DataIdentifier } => 标识区
|
||||
{ Signature } => 签名区
|
||||
{ => 只读区
|
||||
<Payload>
|
||||
}
|
||||
{ => 可变区
|
||||
{ => 受保护区
|
||||
"Empty"
|
||||
}
|
||||
{ => 非受保护区
|
||||
"Empty"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- `SliceNumber`
|
||||
|
||||
```
|
||||
SliceNumber = 205 TLV-LENGTH NoNegativeInteger
|
||||
```
|
||||
|
||||
- `SliceSize`
|
||||
|
||||
```
|
||||
SliceSize = 205 TLV-LENGTH NoNegativeInteger
|
||||
```
|
||||
|
||||
|
||||
## 4. Signature
|
||||
|
||||
```
|
||||
Signature = SignatureInfo SignatureValue
|
||||
|
||||
SignatureInfo = 201 TLV-LENGTH
|
||||
<SignatureType>
|
||||
[KeyLocator]
|
||||
|
||||
SignatureValue = 200 TLV-LENGTH *OCTET
|
||||
```
|
||||
|
||||
在MIN的包格式里面,一个签名 `Signature` 由两个连续的TLV块,`SignatureInfo` 和 `SignatureValue` 组成。
|
||||
|
||||
- **SignatureInfo**
|
||||
|
||||
`SignatureInfo` 中包含一个必选的子 TLV 块 `SignatureType`,它包含了签名的信息,其格式如下:
|
||||
|
||||
```
|
||||
SignatureType = SIGNATURE-TYPE-TYPE TLV-LENGTH <NonNegativeInteger>
|
||||
```
|
||||
|
||||
目前定义的 SignatureType的值如下:
|
||||
|
||||
| SignatureType Value | Description |
|
||||
| :-----------------: | :----------------------------------------------------------: |
|
||||
| 0 | SM2_WITH_SM3,在SM3 Hash摘要的基础上用SM2签名进行完整性和不可否任性保护 |
|
||||
|
||||
`SignatureInfo` 中还包含一个可选的TLV块 `KeyLocator` (虽说是可选,但是这个是为了后期扩展,目前为必选项),它指示了用于签名的证书或者公钥的位置,其格式如下:
|
||||
|
||||
```
|
||||
KeyLocator = KEYLOCATOR-TYPE TLV-TYPE <Identifier>
|
||||
```
|
||||
|
||||
- **SignatureValue**
|
||||
|
||||
`SignatureValue` 中包含了签名的值,是一串字节
|
||||
@@ -43,25 +43,25 @@ public class CanBePrefix implements TlvComponentBase,InitialAble, IEncodingAble
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
// 这是一个存在性组件,所以如果值为false,则无需编码
|
||||
if(!this.canBePrefix){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int totalLength=0;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
int tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvCanBePrefix));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
|
||||
@@ -43,27 +43,27 @@ public class CongestionMark implements TlvComponentBase,InitialAble, IEncodingAb
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
int totalLength=0;
|
||||
|
||||
// 编码 TLV-VALUE
|
||||
int tmplen=encoder.prependNonNegativeInteger(this.congestionMark);
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmplen+=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen+=encoder.prependVarNumber(new VlInt(TLV.TlvCongestionMark));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
@@ -76,7 +76,7 @@ public class CongestionMark implements TlvComponentBase,InitialAble, IEncodingAb
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
// 检查 Type 是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvCongestionMark))){
|
||||
return false;
|
||||
@@ -84,11 +84,7 @@ public class CongestionMark implements TlvComponentBase,InitialAble, IEncodingAb
|
||||
|
||||
// 读取 CongestionMark
|
||||
long value= 0;
|
||||
try {
|
||||
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
|
||||
} catch (VlIntException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
|
||||
if(value<0){
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -43,27 +43,27 @@ public class FreshnessPeriod implements TlvComponentBase,InitialAble, IEncodingA
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
int totalLength=0;
|
||||
|
||||
// 编码 TLV-VALUE
|
||||
int tmplen=encoder.prependNonNegativeInteger(this.freshnessPeriod);
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmplen+=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen+=encoder.prependVarNumber(new VlInt(TLV.TlvFreshnessPeriod));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
@@ -76,7 +76,7 @@ public class FreshnessPeriod implements TlvComponentBase,InitialAble, IEncodingA
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
// 检查 Type 是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvFreshnessPeriod))){
|
||||
return false;
|
||||
@@ -84,11 +84,7 @@ public class FreshnessPeriod implements TlvComponentBase,InitialAble, IEncodingA
|
||||
|
||||
// 读取 value
|
||||
long value= 0;
|
||||
try {
|
||||
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
|
||||
} catch (VlIntException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
|
||||
if(value<0){
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -43,27 +43,27 @@ public class HopLimit implements TlvComponentBase,InitialAble, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
int totalLength=0;
|
||||
|
||||
// 编码 TLV-VALUE
|
||||
int tmplen=encoder.prependNonNegativeInteger(this.hopLimit);
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmplen+=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen+=encoder.prependVarNumber(new VlInt(TLV.TlvHopLimit));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
@@ -71,7 +71,7 @@ public class HopLimit implements TlvComponentBase,InitialAble, IEncodingAble {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
// 检查 Type 是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvHopLimit))){
|
||||
return false;
|
||||
@@ -79,11 +79,7 @@ public class HopLimit implements TlvComponentBase,InitialAble, IEncodingAble {
|
||||
|
||||
// 读取 HopLimit
|
||||
long value= 0;
|
||||
try {
|
||||
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
|
||||
} catch (VlIntException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
|
||||
if(value<0){
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -184,13 +184,13 @@ public class Identifier implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
int totalLength=0;
|
||||
// 编码 TLV-VALUE
|
||||
for (int i = 0; i < components.length(); i++) {
|
||||
int tmpLen=components.getElement(i).wireEncode(encoder);
|
||||
if(tmpLen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmpLen;
|
||||
}
|
||||
@@ -198,14 +198,14 @@ public class Identifier implements TlvComponentBase, IEncodingAble {
|
||||
// 编码 TLV-LENGTH
|
||||
int tmpLen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmpLen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmpLen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmpLen=encoder.prependVarNumber(new VlInt(TLV.TlvIdentifier));
|
||||
if(tmpLen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmpLen;
|
||||
|
||||
|
||||
@@ -120,7 +120,11 @@ public class IdentifierComponent implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
public IdentifierComponent(Block block){
|
||||
this.wireDecode(block);
|
||||
try {
|
||||
this.wireDecode(block);
|
||||
} catch (VlIntException e) {
|
||||
throw new Error("IdentifierComponent: wireDecode error. "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,7 +181,7 @@ public class IdentifierComponent implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
return this.identifierBlock.encode(encoder);
|
||||
}
|
||||
|
||||
@@ -187,16 +191,12 @@ public class IdentifierComponent implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
this.identifierBlock=new Block(block);
|
||||
|
||||
//todo:越界问题
|
||||
int length= 0;
|
||||
try {
|
||||
length = this.identifierBlock.getLength().getVlIntValue2Int();
|
||||
} catch (VlIntException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
length = this.identifierBlock.getLength().getVlIntValue2Int();
|
||||
byte[] value=this.identifierBlock.getValue();
|
||||
|
||||
// 要求TLV-LENGTH至少为1,因为 IdentifierComponent 使用 TLV-VALUE 中的第一个字节作为Marker
|
||||
|
||||
@@ -139,7 +139,7 @@ public class IdentifierField implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
// 如果标识区不存在标识,则是一个无效的MIN包,直接抛出错误
|
||||
if(this.identifiers.length()==0){
|
||||
return 0;
|
||||
@@ -150,7 +150,7 @@ public class IdentifierField implements TlvComponentBase, IEncodingAble {
|
||||
for (int i = this.identifiers.length()-1; i >= 0; i--) {
|
||||
int tmplen=this.identifiers.getElement(i).wireEncode(encoder);
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
}
|
||||
@@ -158,14 +158,14 @@ public class IdentifierField implements TlvComponentBase, IEncodingAble {
|
||||
// 编码 TLV-LENGTH
|
||||
int tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvIdentifierField));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
|
||||
@@ -264,27 +264,27 @@ public class IdentifierWrapper implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
int totalLength=0;
|
||||
|
||||
// 编码 TLV-VALUE
|
||||
int tmplen=this.identifier.wireEncode(encoder);
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen=encoder.prependVarNumber(this.tlvType);
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
|
||||
@@ -43,27 +43,27 @@ public class InterestLifeTime implements TlvComponentBase,InitialAble, IEncoding
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
int totalLength=0;
|
||||
|
||||
// 编码 TLV-VALUE
|
||||
int tmplen=encoder.prependNonNegativeInteger(this.interestLifeTime);
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmplen+=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen+=encoder.prependVarNumber(new VlInt(TLV.TlvInterestLifeTime));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
@@ -76,7 +76,7 @@ public class InterestLifeTime implements TlvComponentBase,InitialAble, IEncoding
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
// 检查 Type 是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvInterestLifeTime))){
|
||||
return false;
|
||||
@@ -84,11 +84,7 @@ public class InterestLifeTime implements TlvComponentBase,InitialAble, IEncoding
|
||||
|
||||
// 读取 value
|
||||
long value= 0;
|
||||
try {
|
||||
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
|
||||
} catch (VlIntException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
|
||||
if(value<0){
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -105,26 +105,26 @@ public class KeyLocator implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
int totalLength=0;
|
||||
// 编码 TLV-VALUE
|
||||
int tmplen=this.identifier.wireEncode(encoder);
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
|
||||
@@ -43,25 +43,25 @@ public class MustBeRefresh implements TlvComponentBase,InitialAble, IEncodingAbl
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
// 这是一个存在性组件,所以如果值为false,则无需编码
|
||||
if(!this.mustBeRefresh){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int totalLength=0;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
int tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvMustBeRefresh));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
|
||||
@@ -57,10 +57,10 @@ public class MutableDangerousField implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
// 如果可变非受保护区没有任何子 TLV,则可以去掉可变非受保护区 TLV
|
||||
if(this.blocks.length()==0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int totalLength=0;
|
||||
@@ -68,23 +68,23 @@ public class MutableDangerousField implements TlvComponentBase, IEncodingAble {
|
||||
// 反向遍历,可以保证解码的时候正向输出
|
||||
for(int i=this.blocks.length()-1;i>=0;i++){
|
||||
int tmplen=encoder.prependBlock(this.blocks.getBlock(i));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
}
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
int tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvReadOnlyField));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
|
||||
@@ -24,37 +24,37 @@ public class MutableField implements TlvComponentBase,IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
int totalLength=0;
|
||||
|
||||
// 编码 TLV—VALUE
|
||||
int tmplen=this.mutableDangerousField.wireEncode(encoder);
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
tmplen=this.mutableProtectField.wireEncode(encoder);
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 如果可变保护区和可变非受保护区均为空,则可以去掉可变区
|
||||
if(totalLength==0){
|
||||
return 0;
|
||||
if(totalLength<=0){
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvMutableField));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
|
||||
@@ -57,10 +57,10 @@ public class MutableProtectField implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
// 如果没有任何子 TLV,则可以去掉它
|
||||
if(this.blocks.length()==0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int totalLength=0;
|
||||
@@ -68,23 +68,23 @@ public class MutableProtectField implements TlvComponentBase, IEncodingAble {
|
||||
// 反向遍历,可以保证解码的时候正向输出
|
||||
for(int i=this.blocks.length()-1;i>=0;i++){
|
||||
int tmplen=encoder.prependBlock(this.blocks.getBlock(i));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
}
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
int tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvReadOnlyField));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
|
||||
@@ -43,27 +43,27 @@ public class NackHeader implements TlvComponentBase,InitialAble, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
int totalLength=0;
|
||||
|
||||
// 编码 TLV-VALUE
|
||||
int tmplen=encoder.prependNonNegativeInteger(this.nackReason);
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmplen+=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen+=encoder.prependVarNumber(new VlInt(TLV.TlvNackHeader));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
@@ -76,7 +76,7 @@ public class NackHeader implements TlvComponentBase,InitialAble, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
// 检查 Type 是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvNackHeader))){
|
||||
return false;
|
||||
@@ -84,11 +84,7 @@ public class NackHeader implements TlvComponentBase,InitialAble, IEncodingAble {
|
||||
|
||||
// 读取 value
|
||||
long value= 0;
|
||||
try {
|
||||
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
|
||||
} catch (VlIntException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
|
||||
if(value<0){
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -53,27 +53,27 @@ public class Nonce implements TlvComponentBase,InitialAble, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
int totalLength=0;
|
||||
|
||||
// 编码 TLV-VALUE
|
||||
int tmplen=encoder.prependNonNegativeInteger(this.nonce);
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmplen+=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen+=encoder.prependVarNumber(new VlInt(TLV.TlvNonce));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
@@ -86,7 +86,7 @@ public class Nonce implements TlvComponentBase,InitialAble, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
// 检查 Type 是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvNonce))){
|
||||
return false;
|
||||
@@ -94,11 +94,7 @@ public class Nonce implements TlvComponentBase,InitialAble, IEncodingAble {
|
||||
|
||||
// 读取 value
|
||||
long value= 0;
|
||||
try {
|
||||
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
|
||||
} catch (VlIntException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
|
||||
if(value<0){
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -63,27 +63,27 @@ public class Payload implements TlvComponentBase,InitialAble, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
int totalLength=0;
|
||||
|
||||
// 编码 TLV-VALUE
|
||||
int tmplen=encoder.prependByteArray(this.value,new SizeT(this.value.length));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmplen+=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen+=encoder.prependVarNumber(new VlInt(TLV.TlvPayload));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class ReadOnlyField implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
// 如果只读区没有任何子 TLV,则可以去掉只读区 TLV
|
||||
if(this.blocks.length()==0){
|
||||
return 0;
|
||||
@@ -68,23 +68,23 @@ public class ReadOnlyField implements TlvComponentBase, IEncodingAble {
|
||||
// 反向遍历,可以保证解码的时候正向输出
|
||||
for(int i=this.blocks.length()-1;i>=0;i++){
|
||||
int tmplen=encoder.prependBlock(this.blocks.getBlock(i));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
}
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
int tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvReadOnlyField));
|
||||
if(tmplen==0){
|
||||
return 0;
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
|
||||
@@ -102,10 +102,10 @@ public class SignatureField implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
// 如果签名区没有签名,则可以直接去掉签名区 TLV,因为它不是必须的
|
||||
if(signatures.length()==0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
int totalLength=0;
|
||||
// 编码 TLV-VALUE
|
||||
@@ -114,12 +114,12 @@ public class SignatureField implements TlvComponentBase, IEncodingAble {
|
||||
Signature newSignature=signatures.getElement(i);
|
||||
int tmplen=newSignature.getSigValue().wireEncode(encoder);
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
tmplen=newSignature.getSigInfo().wireEncode(encoder);
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
}
|
||||
@@ -127,14 +127,14 @@ public class SignatureField implements TlvComponentBase, IEncodingAble {
|
||||
// 编码签名区 TLV-LENGTH
|
||||
int tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码签名区 TLV-TYPE
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvSignatureField));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
@@ -160,7 +160,8 @@ public class SignatureField implements TlvComponentBase, IEncodingAble {
|
||||
ElementContainer subElements=block.getSubElements();
|
||||
int subElementNum=subElements.length();
|
||||
if(subElementNum%2!=0){
|
||||
throw new Error("SignatureField.wireDecode: Invalid SignatureField TLV, require even num sub element");
|
||||
// throw new Error("SignatureField.wireDecode: Invalid SignatureField TLV, require even num sub element");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 存储所有解析到的签名
|
||||
|
||||
@@ -100,27 +100,27 @@ public class SignatureInfo implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
int totalLength=0;
|
||||
// 编码 TLV-VALUE
|
||||
if(!this.keyLocator.isValid()){
|
||||
// KeyLocator 是可选的,如果当前 SignatureInfo 对象有一个有效的 KeyLocator,则对其进行编码
|
||||
int tmplen=this.keyLocator.wireEncode(encoder);
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
}
|
||||
int tmplen=this.signatureType.wireEncode(encoder);
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class SignatureType implements TlvComponentBase, IEncodingAble {
|
||||
* 根据 TLV Block 创建一个 SignatureType
|
||||
* @param block
|
||||
*/
|
||||
public SignatureType(Block block){
|
||||
public SignatureType(Block block) throws VlIntException {
|
||||
this.buildSignatureTypeByBlock(block);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public class SignatureType implements TlvComponentBase, IEncodingAble {
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
public boolean buildSignatureTypeByBlock(Block block){
|
||||
public boolean buildSignatureTypeByBlock(Block block) throws VlIntException {
|
||||
return this.wireDecode(block);
|
||||
}
|
||||
|
||||
@@ -101,27 +101,27 @@ public class SignatureType implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
int totalLength=0;
|
||||
|
||||
// 编码 TLV-VALUE
|
||||
int tmplen=encoder.prependNonNegativeInteger(this.value.getSignatureAlgorithm());
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvSignatureType));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
@@ -134,7 +134,7 @@ public class SignatureType implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
// 检查 Type 是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvSignatureType))){
|
||||
return false;
|
||||
@@ -142,11 +142,11 @@ public class SignatureType implements TlvComponentBase, IEncodingAble {
|
||||
|
||||
// 尝试从 TLE-VALUE 中读取出一个非负整数
|
||||
long result= 0;
|
||||
try {
|
||||
// try {
|
||||
result = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
|
||||
} catch (VlIntException e) {
|
||||
throw new Error("SignatureType.wireDecode: Invalid SignatureType TLV");
|
||||
}
|
||||
// } catch (VlIntException e) {
|
||||
// throw new Error("SignatureType.wireDecode: Invalid SignatureType TLV");
|
||||
// }
|
||||
if(result<0){
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class SignatureValue implements TlvComponentBase, IEncodingAble {
|
||||
* 根据 TLV Block 创建一个 SignatureValue
|
||||
* @param block
|
||||
*/
|
||||
public SignatureValue(Block block){
|
||||
public SignatureValue(Block block) throws VlIntException {
|
||||
this.buildSignatureValueByBlock(block);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class SignatureValue implements TlvComponentBase, IEncodingAble {
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
public boolean buildSignatureValueByBlock(Block block){
|
||||
public boolean buildSignatureValueByBlock(Block block) throws VlIntException {
|
||||
return this.wireDecode(block);
|
||||
}
|
||||
|
||||
@@ -65,26 +65,26 @@ public class SignatureValue implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
int totalLength=0;
|
||||
// 编码 TLV-VALUE
|
||||
int tmplen=encoder.prependByteArray(this.value,new SizeT(this.value.length));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvSignatureValue));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
@@ -97,18 +97,18 @@ public class SignatureValue implements TlvComponentBase, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
// 检查 Type 是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvSignatureValue))){
|
||||
return false;
|
||||
}
|
||||
|
||||
int len= 0;
|
||||
try {
|
||||
// try {
|
||||
len = block.getLength().getVlIntValue2Int();
|
||||
} catch (VlIntException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// } catch (VlIntException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
this.value=new byte[len];
|
||||
System.arraycopy(block.getValue(),0,this.value,0,len);
|
||||
return true;
|
||||
|
||||
@@ -22,7 +22,7 @@ public class TTL implements IEncodingAble {
|
||||
public TTL(){
|
||||
}
|
||||
|
||||
public TTL(Block block){
|
||||
public TTL(Block block) throws VlIntException {
|
||||
buildTTLByBlock(block);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class TTL implements IEncodingAble {
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
public boolean buildTTLByBlock(Block block){
|
||||
public boolean buildTTLByBlock(Block block) throws VlIntException {
|
||||
return this.wireDecode(block);
|
||||
}
|
||||
|
||||
@@ -57,26 +57,26 @@ public class TTL implements IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
int totalLength=0;
|
||||
// 编码 TLV-VALUE
|
||||
int tmpLen=encoder.prependNonNegativeInteger(this.ttl);
|
||||
if(tmpLen==0){
|
||||
return 0;
|
||||
if(tmpLen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmpLen;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmpLen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmpLen==0){
|
||||
return 0;
|
||||
if(tmpLen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmpLen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmpLen=encoder.prependVarNumber(new VlInt(TLV.TlvTTL));
|
||||
if(tmpLen==0){
|
||||
return 0;
|
||||
if(tmpLen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmpLen;
|
||||
|
||||
@@ -89,17 +89,17 @@ public class TTL implements IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
// 检查Type是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvTTL))){
|
||||
return false;
|
||||
}
|
||||
long value= 0;
|
||||
try {
|
||||
// try {
|
||||
value = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
|
||||
} catch (VlIntException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// } catch (VlIntException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
if(value<0){
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Block {
|
||||
* 则会对比解析到的 TLV-LENGTH 与 TLV-VALUE的实际长度是否匹配
|
||||
* @return
|
||||
*/
|
||||
public static Block createBlockByBuffer(byte[] buffer,boolean verifyLength){
|
||||
public static Block createBlockByBuffer(byte[] buffer,boolean verifyLength) throws EncoderException {
|
||||
if(buffer.length==0){
|
||||
return null;
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class Block {
|
||||
* @param verifyLength
|
||||
* @return
|
||||
*/
|
||||
public static Block createBlockByTypeLengthBuffer(VlInt tlvType,VlInt tlvLength,byte[] buffer,boolean verifyLength){
|
||||
public static Block createBlockByTypeLengthBuffer(VlInt tlvType,VlInt tlvLength,byte[] buffer,boolean verifyLength) throws EncoderException {
|
||||
return new Block(tlvType,tlvLength,buffer,verifyLength);
|
||||
}
|
||||
|
||||
@@ -78,33 +78,33 @@ public class Block {
|
||||
* @param buffer
|
||||
* @param verifyLength
|
||||
*/
|
||||
public Block(VlInt tlvType,VlInt tlvLength,byte[] buffer,boolean verifyLength){
|
||||
public Block(VlInt tlvType,VlInt tlvLength,byte[] buffer,boolean verifyLength) throws EncoderException {
|
||||
this.tlvType=tlvType;
|
||||
this.length=tlvLength;
|
||||
|
||||
// 检查长度是否正确
|
||||
if(verifyLength && (!this.length.isEqual(buffer.length))){
|
||||
//todo: 抛出异常
|
||||
throw new Error("Block(VlInt tlvType,VlInt tlvLength,byte[] buffer,boolean verifyLength): invalid length.");
|
||||
}
|
||||
|
||||
// 设置 Raw
|
||||
Encoder encoder=new Encoder();
|
||||
boolean resetBool=encoder.encoderReset(new SizeT(tlvType.size()+tlvLength.size()+buffer.length),new SizeT(0));
|
||||
if(!resetBool){
|
||||
//todo: 抛出异常
|
||||
throw new Error("Block(VlInt tlvType,VlInt tlvLength,byte[] buffer,boolean verifyLength): encoderReset error");
|
||||
}
|
||||
if(encoder.prependByteArray(buffer,new SizeT(buffer.length))==0){
|
||||
//todo: 抛出异常
|
||||
throw new Error("Block(VlInt tlvType,VlInt tlvLength,byte[] buffer,boolean verifyLength): prepenndByteArray buffer error");
|
||||
}
|
||||
if(encoder.prependVarNumber(tlvLength)==0){
|
||||
//todo: 抛出异常
|
||||
throw new Error("Block(VlInt tlvType,VlInt tlvLength,byte[] buffer,boolean verifyLength): prependVarNumber tlvLength error");
|
||||
}
|
||||
if(encoder.prependVarNumber(tlvType)==0){
|
||||
//todo: 抛出异常
|
||||
throw new Error("Block(VlInt tlvType,VlInt tlvLength,byte[] buffer,boolean verifyLength): prependVarNumber tlvType error");
|
||||
}
|
||||
byte[] encodedBuffer=encoder.getBuffer();
|
||||
if(encodedBuffer==null){
|
||||
//todo: 抛出异常
|
||||
throw new Error("Block(VlInt tlvType,VlInt tlvLength,byte[] buffer,boolean verifyLength): encoder.getBuffer error");
|
||||
}
|
||||
this.raw=encodedBuffer;
|
||||
|
||||
@@ -248,8 +248,8 @@ public class Block {
|
||||
}
|
||||
this.addElement(block);
|
||||
start+=tlvLength.getVlIntValue2Int();
|
||||
} catch (VlIntException e) {
|
||||
e.printStackTrace();
|
||||
} catch (VlIntException | EncoderException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -302,7 +302,7 @@ public class Block {
|
||||
* @param encoder
|
||||
* @return
|
||||
*/
|
||||
public int encode(Encoder encoder){
|
||||
public int encode(Encoder encoder) throws EncoderException {
|
||||
// 如果已经有raw,则说明编码过,或者是解码而来的,不用在此Encode
|
||||
if(this.hasRaw()){
|
||||
return encoder.prependByteArray(this.raw,new SizeT(this.raw.length));
|
||||
|
||||
@@ -15,13 +15,13 @@ public interface IEncodingAble {
|
||||
* @param encoder
|
||||
* @return
|
||||
*/
|
||||
public int wireEncode(Encoder encoder);
|
||||
public int wireEncode(Encoder encoder) throws EncoderException;
|
||||
|
||||
/**
|
||||
* 线速解码,将一个TLV解码成一个网络包
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
public boolean wireDecode(Block block);
|
||||
public boolean wireDecode(Block block) throws VlIntException;
|
||||
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class SelfEncodingBase {
|
||||
* @param iEncodingAble
|
||||
* @return
|
||||
*/
|
||||
public Block selfWireEncode(IEncodingAble iEncodingAble){
|
||||
public Block selfWireEncode(IEncodingAble iEncodingAble) throws EncoderException {
|
||||
// this.setiEncodingAble(iEncodingAble);
|
||||
if((this.rawBlock!=null)&&this.rawBlock.isValid()){
|
||||
return this.rawBlock;
|
||||
@@ -64,7 +64,7 @@ public class SelfEncodingBase {
|
||||
* @param iEncodingAble
|
||||
* @return
|
||||
*/
|
||||
private Block easyEncoder(IEncodingAble iEncodingAble){
|
||||
private Block easyEncoder(IEncodingAble iEncodingAble) throws EncoderException {
|
||||
Encoder encoder=new Encoder();
|
||||
|
||||
// 首先测量目标 TLV 的大小
|
||||
|
||||
@@ -51,7 +51,7 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean fillDataToFields() {
|
||||
public boolean fillDataToFields() throws EncoderException{
|
||||
// 可变区 => 受保护区(无)
|
||||
|
||||
// 填充可变区 => 非受保护区
|
||||
@@ -90,7 +90,7 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean extraDataFromFields() {
|
||||
public boolean extraDataFromFields() throws VlIntException {
|
||||
// 提取 Payload
|
||||
Block payloadBlock=this.minPacket.readOnlyField.getBlockByType(new VlInt(TLV.TlvPayload));
|
||||
if(payloadBlock==null){
|
||||
@@ -128,7 +128,7 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
// 首先将属性填充到分区当中
|
||||
if(!this.fillDataToFields()){
|
||||
return 0;
|
||||
@@ -146,7 +146,7 @@ public class CPacket implements InteractWithField, IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
if(!this.minPacket.wireDecode(block)){
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class Data implements IEncodingAble,InteractWithField {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean fillDataToFields() {
|
||||
public boolean fillDataToFields() throws EncoderException {
|
||||
/////////////////////////////////////////////////////////////
|
||||
//// 填充可变区
|
||||
// { => 可变区
|
||||
@@ -146,7 +146,7 @@ public class Data implements IEncodingAble,InteractWithField {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean extraDataFromFields() {
|
||||
public boolean extraDataFromFields() throws VlIntException {
|
||||
/////////////////////////////////////////////////////////////
|
||||
//// 解析可变区
|
||||
// { => 可变区
|
||||
@@ -216,7 +216,7 @@ public class Data implements IEncodingAble,InteractWithField {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
// 首先将各项属性填充到分区当中
|
||||
if(this.fillDataToFields()){
|
||||
return 0;
|
||||
@@ -234,7 +234,7 @@ public class Data implements IEncodingAble,InteractWithField {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
if(!this.minPacket.wireDecode(block)){
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package packet;
|
||||
|
||||
import encoding.EncoderException;
|
||||
import encoding.VlIntException;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description: 定义了一个网络包应该实现哪些和分区交互的方法
|
||||
@@ -12,11 +15,11 @@ public interface InteractWithField {
|
||||
* 将包的属性填充到网络包的四个分区当中
|
||||
* @return
|
||||
*/
|
||||
boolean fillDataToFields();
|
||||
boolean fillDataToFields() throws EncoderException;
|
||||
|
||||
/**
|
||||
* 从网络包的四个分区当中提取出特定网络包的相关属性
|
||||
* @return
|
||||
*/
|
||||
boolean extraDataFromFields();
|
||||
boolean extraDataFromFields() throws VlIntException;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public class Interest implements InteractWithField,IEncodingAble{
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean fillDataToFields() {
|
||||
public boolean fillDataToFields() throws EncoderException {
|
||||
/////////////////////////////////////////////////////////////
|
||||
//// 填充可变区
|
||||
/////////////////////////////////////////////////////////////
|
||||
@@ -201,7 +201,7 @@ public class Interest implements InteractWithField,IEncodingAble{
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean extraDataFromFields() {
|
||||
public boolean extraDataFromFields() throws VlIntException {
|
||||
/////////////////////////////////////////////////////////////
|
||||
//// 解析可变区
|
||||
// { => 可变区
|
||||
@@ -292,7 +292,7 @@ public class Interest implements InteractWithField,IEncodingAble{
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
// 首先将各项属性填充到分区当中
|
||||
if(!this.fillDataToFields()){
|
||||
return 0;
|
||||
@@ -310,7 +310,7 @@ public class Interest implements InteractWithField,IEncodingAble{
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
public boolean wireDecode(Block block) throws VlIntException {
|
||||
if(!this.minPacket.wireDecode(block)){
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class MINPacket implements IEncodingAble {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
public int wireEncode(Encoder encoder) throws EncoderException {
|
||||
if(!this.isPacketValid()){
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user