MCPcopy
hub / github.com/aceld/zinx / Intercept

Method Intercept

zdecoder/tlvdecoder.go:113–144  ·  view source on GitHub ↗
(chain ziface.IChain)

Source from the content-addressed store, hash-verified

111}
112
113func (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}

Callers

nothing calls this directly

Calls 7

decodeMethod · 0.95
GetIMessageMethod · 0.65
ProceedWithIMessageMethod · 0.65
GetDataMethod · 0.65
SetMsgIDMethod · 0.65
SetDataMethod · 0.65
SetDataLenMethod · 0.65

Tested by

no test coverage detected