首页 > 代码库 > golang的指针到string,string到指针的转换

golang的指针到string,string到指针的转换

由于某个需求,需要如题的转换,废话不多说,直接贴代码了,其实挺丑了,备用了

func (this *Server) socketParserHandler(client *genTcpServer.Client, fullData []byte) {    fmt.Println("original data is", client)    strPointerHex := fmt.Sprintf("%p", unsafe.Pointer(client))    fmt.Println("connection is", strPointerHex)    strPointerInt := fmt.Sprintf("%d", unsafe.Pointer(client))    fmt.Println("connection is", strPointerInt)    i, _ := strconv.ParseInt(strPointerInt, 10, 0)    var pointer *genTcpServer.Client    pointer = *(**genTcpServer.Client)(unsafe.Pointer(&i))    fmt.Println("connection pointer is", pointer)    debugMsg := fmt.Sprintf("%p", unsafe.Pointer(pointer))    fmt.Println("debugMsg is", debugMsg)