github.com/jhump/protocompile@v0.0.0-20221021153901-4f6f732835e8/linker/pathkey_unsafe.go (about) 1 //go:build !appengine && !gopherjs && !purego 2 // +build !appengine,!gopherjs,!purego 3 4 // NB: other environments where unsafe is inappropriate should use "purego" build tag 5 // https://github.com/golang/go/issues/23172 6 7 package linker 8 9 import ( 10 "reflect" 11 "unsafe" 12 13 "google.golang.org/protobuf/reflect/protoreflect" 14 ) 15 16 var pathElementType = reflect.TypeOf(protoreflect.SourcePath{}).Elem() 17 18 func pathKey(p protoreflect.SourcePath) interface{} { 19 hdr := (*reflect.SliceHeader)(unsafe.Pointer(reflect.ValueOf(&p).Pointer())) 20 array := reflect.NewAt(reflect.ArrayOf(hdr.Len, pathElementType), unsafe.Pointer(hdr.Data)) 21 return array.Elem().Interface() 22 }