(chain ziface.IChain)
| 112 | } |
| 113 | |
| 114 | func (ltv *LTV_Little_Decoder) Intercept(chain ziface.IChain) ziface.IcResp { |
| 115 | //1. Get the IMessage of zinx |
| 116 | iMessage := chain.GetIMessage() |
| 117 | if iMessage == nil { |
| 118 | // Go to the next layer in the chain of responsibility |
| 119 | return chain.ProceedWithIMessage(iMessage, nil) |
| 120 | } |
| 121 | |
| 122 | //2. Get Data |
| 123 | data := iMessage.GetData() |
| 124 | //zlog.Ins().DebugF("LTV-RawData size:%d data:%s\n", len(data), hex.EncodeToString(data)) |
| 125 | |
| 126 | //3. If the amount of data read is less than the length of the header, proceed to the next layer directly. |
| 127 | // (读取的数据不超过包头,直接进入下一层) |
| 128 | if len(data) < LTV_HEADER_SIZE { |
| 129 | return chain.ProceedWithIMessage(iMessage, nil) |
| 130 | } |
| 131 | |
| 132 | //4. LTV Decode |
| 133 | ltvData := ltv.decode(data) |
| 134 | |
| 135 | //5. Set the decoded data back to the IMessage, the Zinx Router needs MsgID for addressing |
| 136 | // (将解码后的数据重新设置到IMessage中, Zinx的Router需要MsgID来寻址) |
| 137 | iMessage.SetDataLen(ltvData.Length) |
| 138 | iMessage.SetMsgID(ltvData.Tag) |
| 139 | iMessage.SetData(ltvData.Value) |
| 140 | |
| 141 | //6. Pass the decoded data to the next layer. |
| 142 | // (将解码后的数据进入下一层) |
| 143 | return chain.ProceedWithIMessage(iMessage, *ltvData) |
| 144 | } |
nothing calls this directly
no test coverage detected