discovery: Use naming.Join() to separate parts for global discovery.
Change-Id: I69cf907a214554ef894c54235df15593fa310bab
diff --git a/lib/discovery/global/encoding.go b/lib/discovery/global/encoding.go
index 774f5aa..9bb0a59 100644
--- a/lib/discovery/global/encoding.go
+++ b/lib/discovery/global/encoding.go
@@ -12,8 +12,6 @@
"v.io/v23/vom"
)
-const suffixDelim = ","
-
// encodeAdToSuffix encodes the ad.Id and the ad.Attributes into the suffix at
// which we mount the advertisement.
//
@@ -26,30 +24,26 @@
}
// Escape suffixDelim to use it as our delimeter between the id and the attrs.
id := ad.Id.String()
- attr := naming.Escape(string(b), suffixDelim)
- return naming.EncodeAsNameElement(id + suffixDelim + attr), nil
+ attr := naming.EncodeAsNameElement(string(b))
+ return naming.Join(id, attr), nil
}
// decodeAdFromSuffix decodes s into an advertisement.
func decodeAdFromSuffix(in string) (*discovery.Advertisement, error) {
- s, ok := naming.DecodeFromNameElement(in)
- if !ok {
- return nil, NewErrAdInvalidEncoding(nil, in)
- }
- parts := strings.Split(s, suffixDelim)
+ parts := strings.SplitN(in, "/", 2)
if len(parts) != 2 {
return nil, NewErrAdInvalidEncoding(nil, in)
}
id, attrs := parts[0], parts[1]
+ attrs, ok := naming.DecodeFromNameElement(attrs)
+ if !ok {
+ return nil, NewErrAdInvalidEncoding(nil, in)
+ }
ad := &discovery.Advertisement{}
var err error
if ad.Id, err = discovery.ParseAdId(id); err != nil {
return nil, err
}
- attrs, ok = naming.Unescape(attrs)
- if !ok {
- return nil, NewErrAdInvalidEncoding(nil, in)
- }
if err = vom.Decode([]byte(attrs), &ad.Attributes); err != nil {
return nil, err
}
diff --git a/lib/discovery/global/scan.go b/lib/discovery/global/scan.go
index f336b77..dec7be0 100644
--- a/lib/discovery/global/scan.go
+++ b/lib/discovery/global/scan.go
@@ -57,11 +57,15 @@
}
}
- // Now that the key is either empty or an AdId, we suffix it with "*".
// In the case of empty, we need to scan for everything.
// In the case where target is a AdId we need to scan for entries prefixed with
// the AdId with any encoded attributes afterwards.
- scanCh, err := d.ns.Glob(ctx, target+"*")
+ if len(target) == 0 {
+ target = naming.Join("*", "*")
+ } else {
+ target = naming.Join(target, "*")
+ }
+ scanCh, err := d.ns.Glob(ctx, target)
if err != nil {
return nil, err
}