Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Unified Diff: service/datastore/key.go

Issue 1397673003: Add Gob encoding functions for Key. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/key.go
diff --git a/service/datastore/key.go b/service/datastore/key.go
index b2b9e45f37da085b33f76f68f0f7d9ea5b791dc5..227858858bc76da9850d0ecb019ca1ed6eac8320 100644
--- a/service/datastore/key.go
+++ b/service/datastore/key.go
@@ -320,6 +320,21 @@ func (k *Key) UnmarshalJSON(buf []byte) error {
return nil
}
+// GobEncode allows the Key to be encoded in a Gob struct.
+func (k *Key) GobEncode() ([]byte, error) {
+ return []byte(k.Encode()), nil
+}
+
+// GobDecode allows the Key to be decoded in a Gob struct.
+func (k *Key) GobDecode(buf []byte) error {
+ nk, err := NewKeyEncoded(string(buf))
+ if err != nil {
+ return err
+ }
+ *k = *nk
+ return nil
+}
+
// Root returns the entity root for the given key.
func (k *Key) Root() *Key {
if len(k.toks) > 1 {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698