/** * @Author : zou.yingbin * @Create : 2022/3/26 14:52 * @Modify : 2022/3/26 14:52 * @note : */ package client import ( "mtp20access/packet" ) // DispatchRealQuote 分发行情 func DispatchRealQuote(p *packet.MiQuotePacket, clinet *Client) { // TODO: 目前只实现了订阅发送模式, 未支持全部发送模式 // 解析接收到的商品 // ware := parseWareInfo(p) // if len(ware) == 1 { // // 只有一个商品, 不需要重新打包,提高效率 // v := ware[0] // if s, ok := subMgr.getSession(v.exchId, v.goodsCode); ok { // for i := range s { // err := clinet.WriteBuf(p.OriMsg) // if err != nil { // // Logger().Errorf("%s push quote error:%v", s[i].info(), err) // } // } // } // } else { // // 分发行情到链接 // for _, v := range ware { // if s, ok := subMgr.getSession(v.exchId, v.goodsCode); ok { // // 按商品重新打包 // quote := packet.MiQuotePacket{ // BigType: p.BigType, // SmallType: p.SmallType, // SerialNum: p.SerialNum, // Mode: p.Mode, // } // quote.Msg = v.buf // sendBuf := quote.EnPack() // for i := range s { // err := s[i].WriteBuf(sendBuf) // if err != nil { // // Logger().Errorf("%s push quote error:%v", s[i].info(), err) // } // } // } // } // } clinet.WriteWsBuf(p.OriMsg) } // parseWareInfo 从报文中解析出所有报价商品 func parseWareInfo(p *packet.MiQuotePacket) []wareInfo { data := p.OriMsg[14:] ware := make([]wareInfo, 0) nPos1, nPos2 := -1, -1 for i := 0; i < len(data); i++ { // 报价包开始 if data[i] == 0x10 { nPos1 = i } // 报价包结束 if data[i] == 0x11 { nPos2 = i + 1 } if nPos1 >= 0 && nPos2 > 0 { v := wareInfo{buf: data[nPos1:nPos2]} v.parseField() //v.printInfo() //v.debugPrintAllField() ware = append(ware, v) // 重置nPos1, nPos2 继续查找下一个报价包 nPos1, nPos2 = -1, -1 } } return ware }