(chain ziface.IChain)
| 111 | } |
| 112 | |
| 113 | func (tlv *TLVDecoder) Intercept(chain ziface.IChain) ziface.IcResp { |
| 114 | |
| 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("TLV-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) < TLV_HEADER_SIZE { |
| 129 | return chain.ProceedWithIMessage(iMessage, nil) |
| 130 | } |
| 131 | |
| 132 | //4. TLV Decode |
| 133 | tlvData := tlv.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.SetMsgID(tlvData.Tag) |
| 138 | iMessage.SetData(tlvData.Value) |
| 139 | iMessage.SetDataLen(tlvData.Length) |
| 140 | |
| 141 | //6. Pass the decoded data to the next layer. |
| 142 | // (将解码后的数据进入下一层) |
| 143 | return chain.ProceedWithIMessage(iMessage, *tlvData) |
| 144 | } |
nothing calls this directly
no test coverage detected