github.com/jhump/protocompile@v0.0.0-20221021153901-4f6f732835e8/linker/pathkey_no_unsafe.go (about)

     1  //go:build appengine || gopherjs || purego
     2  // +build appengine gopherjs purego
     3  
     4  // NB: other environments where unsafe is unappropriate should use "purego" build tag
     5  // https://github.com/golang/go/issues/23172
     6  
     7  package linker
     8  
     9  import (
    10  	"reflect"
    11  
    12  	"google.golang.org/protobuf/reflect/protoreflect"
    13  )
    14  
    15  func pathKey(p protoreflect.SourcePath) interface{} {
    16  	rv := reflect.ValueOf(p)
    17  	arrayType := reflect.ArrayOf(rv.Len(), rv.Type().Elem())
    18  	array := reflect.New(arrayType).Elem()
    19  	reflect.Copy(array, rv)
    20  	return array.Interface()
    21  }