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

Unified Diff: impl/memory/datastore_query.go

Issue 1309933003: datastore: Add DecodeCursor to [Raw]Interface. (Closed) Base URL: https://github.com/luci/gae@master
Patch Set: Use more concise formulation. Created 5 years, 4 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 | « impl/memory/datastore.go ('k') | impl/prod/raw_datastore.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/datastore_query.go
diff --git a/impl/memory/datastore_query.go b/impl/memory/datastore_query.go
index a9b22f2efb9c5abb05684e8fe22076872ce66e98..c04c44f278fe739478d4bbaa3353b58c42258276 100644
--- a/impl/memory/datastore_query.go
+++ b/impl/memory/datastore_query.go
@@ -5,6 +5,7 @@
package memory
import (
+ "encoding/base64"
"errors"
"fmt"
"math"
@@ -63,7 +64,7 @@ func parseFilter(f string) (prop string, op queryOp, err error) {
type queryCursor string
-func (q queryCursor) String() string { return string(q) }
+func (q queryCursor) String() string { return base64.URLEncoding.EncodeToString([]byte(q)) }
func (q queryCursor) Valid() bool { return q != "" }
type queryIneqFilter struct {
@@ -73,6 +74,18 @@ type queryIneqFilter struct {
high *string
}
+func decodeCursor(s string) (ds.Cursor, error) {
+ d, err := base64.URLEncoding.DecodeString(s)
+ if err != nil {
+ return nil, fmt.Errorf("Failed to Base64-decode cursor: %s", err)
+ }
+ c := queryCursor(string(d))
+ if !c.Valid() {
+ return nil, errors.New("Decoded cursor is not valid.")
+ }
+ return c, nil
+}
+
func increment(bstr string, positive bool) string {
lastIdx := len(bstr) - 1
last := bstr[lastIdx]
« no previous file with comments | « impl/memory/datastore.go ('k') | impl/prod/raw_datastore.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698