func protoToKey(r *pb.Reference) (k *Key, err error) {
	appID := proto.GetString(r.App)
	namespace := proto.GetString(r.NameSpace)
	for _, e := range r.Path.Element {
		k = &Key{
			kind:      proto.GetString(e.Type),
			stringID:  proto.GetString(e.Name),
			intID:     proto.GetInt64(e.Id),
			parent:    k,
			appID:     appID,
			namespace: namespace,
		}
		if !k.valid() {
			return nil, ErrInvalidKey
		}
	}
	return
}
protoToKey converts a Reference proto to a *Key.
package datastore
import (
	"errors"
	"fmt"
	"reflect"
	"appengine"
	"appengine_internal"
	"code.google.com/p/goprotobuf/proto"
	pb "appengine_internal/datastore"
)
var (
	ErrInvalidEntityType = errors.New("datastore: invalid entity type")
	ErrInvalidKey = errors.New("datastore: invalid key")
	ErrNoSuchEntity = errors.New("datastore: no such entity")
)
type ErrFieldMismatch struct {
	StructType reflect.Type
	FieldName  string
	Reason     string
}
func (e *ErrFieldMismatch) Error() string {
	return fmt.Sprintf("datastore: cannot load field %q into a %q: %s",
		e.FieldName, e.StructType, e.Reason)
}