Index: service/rawdatastore/datastore_key.go |
diff --git a/helper/datastore_key.go b/service/rawdatastore/datastore_key.go |
similarity index 65% |
rename from helper/datastore_key.go |
rename to service/rawdatastore/datastore_key.go |
index bfd55edc63dfb418746a57c0baf2e61949d11b1f..672842cccd1e2f1a133c7eda277ef0f57114aab0 100644 |
--- a/helper/datastore_key.go |
+++ b/service/rawdatastore/datastore_key.go |
@@ -4,7 +4,7 @@ |
// adapted from github.com/golang/appengine/datastore |
-package helper |
+package rawdatastore |
import ( |
"bytes" |
@@ -13,17 +13,16 @@ import ( |
"strconv" |
"strings" |
- "github.com/luci/gae" |
- pb "github.com/luci/gae/helper/internal/protos/datastore" |
+ pb "github.com/luci/gae/service/rawdatastore/internal/protos/datastore" |
"github.com/golang/protobuf/proto" |
) |
-// DSKeyEncode encodes the provided key as a base64-encoded protobuf. |
+// KeyEncode encodes the provided key as a base64-encoded protobuf. |
// |
// This encoding is compatible with the SDK-provided encoding and is agnostic |
-// to the underlying implementation of the DSKey. |
-func DSKeyEncode(k gae.DSKey) string { |
+// to the underlying implementation of the Key. |
+func KeyEncode(k Key) string { |
n := 0 |
for i := k; i != nil; i = i.Parent() { |
n++ |
@@ -64,13 +63,13 @@ func DSKeyEncode(k gae.DSKey) string { |
return strings.TrimRight(base64.URLEncoding.EncodeToString(r), "=") |
} |
-// DSKeyToksDecode decodes a base64-encoded protobuf representation of a DSKey |
+// KeyToksDecode decodes a base64-encoded protobuf representation of a Key |
// into a tokenized form. This is so that implementations of the gae wrapper |
-// can decode to their own implementation of DSKey. |
+// can decode to their own implementation of Key. |
// |
// This encoding is compatible with the SDK-provided encoding and is agnostic |
-// to the underlying implementation of the DSKey. |
-func DSKeyToksDecode(encoded string) (appID, namespace string, toks []gae.DSKeyTok, err error) { |
+// to the underlying implementation of the Key. |
+func KeyToksDecode(encoded string) (appID, namespace string, toks []KeyTok, err error) { |
// Re-add padding |
if m := len(encoded) % 4; m != 0 { |
encoded += strings.Repeat("=", 4-m) |
@@ -87,9 +86,9 @@ func DSKeyToksDecode(encoded string) (appID, namespace string, toks []gae.DSKeyT |
appID = r.GetApp() |
namespace = r.GetNameSpace() |
- toks = make([]gae.DSKeyTok, len(r.Path.Element)) |
+ toks = make([]KeyTok, len(r.Path.Element)) |
for i, e := range r.Path.Element { |
- toks[i] = gae.DSKeyTok{ |
+ toks[i] = KeyTok{ |
Kind: e.GetType(), |
IntID: e.GetId(), |
StringID: e.GetName(), |
@@ -98,28 +97,28 @@ func DSKeyToksDecode(encoded string) (appID, namespace string, toks []gae.DSKeyT |
return |
} |
-// DSKeyMarshalJSON returns a MarshalJSON-compatible serialization of a DSKey. |
-func DSKeyMarshalJSON(k gae.DSKey) ([]byte, error) { |
- return []byte(`"` + DSKeyEncode(k) + `"`), nil |
+// KeyMarshalJSON returns a MarshalJSON-compatible serialization of a Key. |
+func KeyMarshalJSON(k Key) ([]byte, error) { |
+ return []byte(`"` + KeyEncode(k) + `"`), nil |
} |
-// DSKeyUnmarshalJSON returns the tokenized version of a DSKey as encoded by |
-// DSKeyMarshalJSON. |
-func DSKeyUnmarshalJSON(buf []byte) (appID, namespace string, toks []gae.DSKeyTok, err error) { |
+// KeyUnmarshalJSON returns the tokenized version of a Key as encoded by |
+// KeyMarshalJSON. |
+func KeyUnmarshalJSON(buf []byte) (appID, namespace string, toks []KeyTok, err error) { |
if len(buf) < 2 || buf[0] != '"' || buf[len(buf)-1] != '"' { |
err = errors.New("datastore: bad JSON key") |
} else { |
- appID, namespace, toks, err = DSKeyToksDecode(string(buf[1 : len(buf)-1])) |
+ appID, namespace, toks, err = KeyToksDecode(string(buf[1 : len(buf)-1])) |
} |
return |
} |
-// DSKeyIncomplete returns true iff k doesn't have an id yet. |
-func DSKeyIncomplete(k gae.DSKey) bool { |
+// KeyIncomplete returns true iff k doesn't have an id yet. |
+func KeyIncomplete(k Key) bool { |
return k != nil && k.StringID() == "" && k.IntID() == 0 |
} |
-// DSKeyValid determines if a key is valid, according to a couple rules: |
+// KeyValid determines if a key is valid, according to a couple rules: |
// - k is not nil |
// - k's namespace matches ns |
// - every token of k: |
@@ -127,7 +126,7 @@ func DSKeyIncomplete(k gae.DSKey) bool { |
// - token's kind and appid are non-blank |
// - token is not incomplete |
// - all tokens have the same namespace and appid |
-func DSKeyValid(k gae.DSKey, ns string, allowSpecial bool) bool { |
+func KeyValid(k Key, ns string, allowSpecial bool) bool { |
if k == nil { |
return false |
} |
@@ -147,7 +146,7 @@ func DSKeyValid(k gae.DSKey, ns string, allowSpecial bool) bool { |
return false |
} |
if k.Parent() != nil { |
- if DSKeyIncomplete(k.Parent()) { |
+ if KeyIncomplete(k.Parent()) { |
return false |
} |
if k.Parent().AppID() != k.AppID() || k.Parent().Namespace() != k.Namespace() { |
@@ -158,16 +157,16 @@ func DSKeyValid(k gae.DSKey, ns string, allowSpecial bool) bool { |
return true |
} |
-// DSKeyRoot returns the entity root for the given key. |
-func DSKeyRoot(k gae.DSKey) gae.DSKey { |
+// KeyRoot returns the entity root for the given key. |
+func KeyRoot(k Key) Key { |
for k != nil && k.Parent() != nil { |
k = k.Parent() |
} |
return k |
} |
-// DSKeysEqual returns true iff the two keys represent identical key values. |
-func DSKeysEqual(a, b gae.DSKey) (ret bool) { |
+// KeysEqual returns true iff the two keys represent identical key values. |
+func KeysEqual(a, b Key) (ret bool) { |
ret = (a.Kind() == b.Kind() && |
a.StringID() == b.StringID() && |
a.IntID() == b.IntID() && |
@@ -177,10 +176,10 @@ func DSKeysEqual(a, b gae.DSKey) (ret bool) { |
return |
} |
ap, bp := a.Parent(), b.Parent() |
- return (ap == nil && bp == nil) || DSKeysEqual(ap, bp) |
+ return (ap == nil && bp == nil) || KeysEqual(ap, bp) |
} |
-func marshalDSKey(b *bytes.Buffer, k gae.DSKey) { |
+func marshalDSKey(b *bytes.Buffer, k Key) { |
if k.Parent() != nil { |
marshalDSKey(b, k.Parent()) |
} |
@@ -194,9 +193,9 @@ func marshalDSKey(b *bytes.Buffer, k gae.DSKey) { |
} |
} |
-// DSKeyString returns a human-readable representation of the key, and is the |
-// typical implementation of DSKey.String() (though it isn't guaranteed to be) |
-func DSKeyString(k gae.DSKey) string { |
+// KeyString returns a human-readable representation of the key, and is the |
+// typical implementation of Key.String() (though it isn't guaranteed to be) |
+func KeyString(k Key) string { |
if k == nil { |
return "" |
} |
@@ -205,14 +204,14 @@ func DSKeyString(k gae.DSKey) string { |
return b.String() |
} |
-// DSKeySplit splits the key into its constituent parts. Note that if the key is |
-// not DSKeyValid, this method may not provide a round-trip for k. |
-func DSKeySplit(k gae.DSKey) (appID, namespace string, toks []gae.DSKeyTok) { |
+// KeySplit splits the key into its constituent parts. Note that if the key is |
+// not KeyValid, this method may not provide a round-trip for k. |
+func KeySplit(k Key) (appID, namespace string, toks []KeyTok) { |
if k == nil { |
return |
} |
- if sk, ok := k.(*GenericDSKey); ok { |
+ if sk, ok := k.(*GenericKey); ok { |
if sk == nil { |
return |
} |
@@ -223,7 +222,7 @@ func DSKeySplit(k gae.DSKey) (appID, namespace string, toks []gae.DSKeyTok) { |
for i := k; i != nil; i = i.Parent() { |
n++ |
} |
- toks = make([]gae.DSKeyTok, n) |
+ toks = make([]KeyTok, n) |
for i := k; i != nil; i = i.Parent() { |
n-- |
toks[n].IntID = i.IntID() |