func GenPacketFromData(data []byte, LOG *log.Logger) *Packet { dataLen := utils.BytesToInt16(data[Length_INDEX:Length_END]) tunnelId := utils.BytesToUint64(data[TunnelId_INDEX:TunnelId_END]) sessionId := utils.BytesToUint32(data[SessionId_INDEX:SessionId_END]) id := utils.BytesToUint32(data[Id_INDEX:Id_END]) protocal := data[ProtoType_INDEX] packetType := data[PacketType_INDEX] otherTunnelId := utils.BytesToUint64(data[OtherTunnelId_INDEX:OtherTunnelId_END]) otherLen := int(data[OtherLen_INDEX]) start := OtherLen_INDEX + 1 dst := "" if otherLen != 0 { log.Println("dst len", otherLen) start += int(otherLen) dst = string(data[OtherLen_INDEX+1 : otherLen+OtherLen_INDEX+1]) } p := new(Packet) p.Length = dataLen p.TunnelId = tunnelId p.SessionId = sessionId p.Id = id p.ProtoType = protocal p.PacketType = packetType p.OtherTunnelId = otherTunnelId p.Start = start p.Dst = dst p.RawData = data p.LOG = LOG return p }
/** 返回所有任务索引数组 **/ func GetAllTaskIndex() ([]Entity.TaskAddr, error) { bufReader := IndexStore.Get() var gobTypeList []Entity.TaskAddr for { var gobType Entity.TaskAddr dataLenBuf := make([]byte, 4) //得到数据体长度 _, err := bufReader.Read(dataLenBuf) if err != nil { Utils.LogInfo("err=%d\n", err) if err == io.EOF { break } return nil, err } dataLen := Utils.BytesToUint32(dataLenBuf) dataBuf := make([]byte, dataLen) _, err = bufReader.Read(dataBuf) Utils.LogInfo("read file index=%#v\n", dataBuf) if err != nil { Utils.LogInfo("err=%d\n", err) return nil, err } rgob := gob.NewDecoder(bytes.NewBuffer(dataBuf)) err = rgob.Decode(&gobType) if err != nil { Utils.LogInfo("gob index err=%d\n", err) return nil, Utils.LogErr(err) } gobTypeList = append(gobTypeList[:], gobType) } Utils.LogInfo("retn index=%#v\n", gobTypeList) return gobTypeList, nil }
func (cc *CConn) ReadInt(num int) (int, error) { data, err := Utils.ReadConn(num, cc.conn) if err != nil { return 0, err } // Utils.LogInfo("read data=%#v\n",data) return int(Utils.BytesToUint32(data)), nil }