func keyToProto(defaultAppID string, k *Key) *pb.Reference {
	appID := k.appID
	if appID == "" {
		appID = defaultAppID
	}
	n := 0
	for i := k; i != nil; i = i.parent {
		n++
	}
	e := make([]*pb.Path_Element, n)
	for i := k; i != nil; i = i.parent {
		n--
		e[n] = &pb.Path_Element{
			Type: &i.kind,
		}
		// At most one of {Name,Id} should be set.
		// Neither will be set for incomplete keys.
		if i.stringID != "" {
			e[n].Name = &i.stringID
		} else if i.intID != 0 {
			e[n].Id = &i.intID
		}
	}
	var namespace *string
	if k.namespace != "" {
		namespace = proto.String(k.namespace)
	}
	return &pb.Reference{
		App:       proto.String(appID),
		NameSpace: namespace,
		Path: &pb.Path{
			Element: e,
		},
	}
}
func keyToProto(defaultAppID string, k *Key) *pb.Reference {
	appID := k.appID
	if appID == "" {
		appID = defaultAppID
	}
	n := 0
	for i := k; i != nil; i = i.parent {
		n++
	}
	e := make([]*pb.Path_Element, n)
	for i := k; i != nil; i = i.parent {
		n--
		e[n] = &pb.Path_Element{
			Type: &i.kind,
		}
		
		
		if i.stringID != "" {
			e[n].Name = &i.stringID
		} else if i.intID != 0 {
			e[n].Id = &i.intID
		}
	}
	var namespace *string
	if k.namespace != "" {
		namespace = proto.String(k.namespace)
	}
	return &pb.Reference{
		App:       proto.String(appID),
		NameSpace: namespace,
		Path: &pb.Path{
			Element: e,
		},
	}
}
func keyToProto ( defaultAppID string , k * Key ) * pb . Reference { appID := k . appID if appID == " " { appID = defaultAppID } n := 0 for i := k ; i != nil ; i = i . parent { n ++ } e := make ( [ ] * pb . Path_Element , n ) for i := k ; i != nil ; i = i . parent { n -- e [ n ] = & pb . Path_Element { Type : & i . kind , } // At most one of {Name,Id} should be set. // Neither will be set for incomplete keys. if i . stringID != " " { e [ n ] . Name = & i . stringID } else if i . intID != 0 { e [ n ] . Id = & i . intID } } var namespace * string if k . namespace != " " { namespace = proto . String ( k . namespace ) } return & pb . Reference { App : proto . String ( appID ) , NameSpace : namespace , Path : & pb . Path { Element : e , } , } }
// keyToProto converts a *Key to a Reference proto.
keyToProto converts a * Key to a Reference proto .