cheliequan
2023-02-03 9f24b2f398b7da6b95fbe3642d716575db5d8700
api/bhsgo/bhome_node.go
@@ -8,10 +8,27 @@
import "C"
import (
   "reflect"
   "unsafe"
   bh "basic.com/valib/c_bhomebus.git/proto/source/bhome_msg"
)
func unsafeGetBytes(s string) []byte {
   const MaxInt32 = 1<<31 - 1
   return (*[MaxInt32]byte)(unsafe.Pointer((*reflect.StringHeader)(
      unsafe.Pointer(&s)).Data))[: len(s)&MaxInt32 : len(s)&MaxInt32]
}
func ByteSlice2String(bs []byte) string {
   return *(*string)(unsafe.Pointer(&bs))
}
/*func unsafeGetBytes(s string) []byte {
    return (*[0x7fff0000]byte)(unsafe.Pointer(
        (*reflect.StringHeader)(unsafe.Pointer(&s)).Data),
    )[:len(s):len(s)]
}*/
func getPtr(n *[]byte) unsafe.Pointer {
   if len(*n) > 0 {
@@ -150,8 +167,13 @@
   defer C.BHFree(cpid, cpid_len)
   defer C.BHFree(creply, creply_len)
   if r {
      *proc_id = string(C.GoBytes(cpid, cpid_len))
      pub.Unmarshal(C.GoBytes(creply, creply_len))
      //*proc_id = string(C.GoBytes(cpid, cpid_len))
      //pub.Unmarshal(C.GoBytes(creply, creply_len))
      //const MaxInt32 = 1<<32 - 1
      const maxLen = 0x7fffffff
      *proc_id = ByteSlice2String((*[maxLen]byte)(unsafe.Pointer(cpid))[:cpid_len:cpid_len])
      pub.Unmarshal((*[maxLen]byte)(unsafe.Pointer(creply))[:creply_len:creply_len])
   }
   return r