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

Unified Diff: go/src/infra/gae/libs/gae/helper/serialize.go

Issue 1231863018: Fix DSKey encoding. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: add test Created 5 years, 5 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 | go/src/infra/gae/libs/gae/helper/serialize_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/gae/libs/gae/helper/serialize.go
diff --git a/go/src/infra/gae/libs/gae/helper/serialize.go b/go/src/infra/gae/libs/gae/helper/serialize.go
index 98f67b9cfa5091e6296483348babeeae7f5387d5..34a8d4b7568aedc72db94e99a5884a451c715296 100644
--- a/go/src/infra/gae/libs/gae/helper/serialize.go
+++ b/go/src/infra/gae/libs/gae/helper/serialize.go
@@ -112,10 +112,13 @@ func ReadDSKey(buf *bytes.Buffer, context DSKeyContext, appid, namespace string)
// WriteDSKeyTok writes a DSKeyTok to the buffer. You usually want WriteDSKey
// instead of this.
func WriteDSKeyTok(buf *bytes.Buffer, tok gae.DSKeyTok) {
- // tok.kind ++ tok.stringID ++ tok.intID?
+ // tok.kind ++ typ ++ [tok.stringID || tok.intID]
cmpbin.WriteString(buf, tok.Kind)
- cmpbin.WriteString(buf, tok.StringID)
- if tok.StringID == "" {
+ if tok.StringID != "" {
+ buf.WriteByte(byte(gae.DSPTString))
+ cmpbin.WriteString(buf, tok.StringID)
+ } else {
+ buf.WriteByte(byte(gae.DSPTInt))
cmpbin.WriteInt(buf, tok.IntID)
}
}
@@ -126,17 +129,20 @@ func ReadDSKeyTok(buf *bytes.Buffer) (ret gae.DSKeyTok, err error) {
if ret.Kind, _, err = cmpbin.ReadString(buf); err != nil {
return
}
- if ret.StringID, _, err = cmpbin.ReadString(buf); err != nil {
+ typ, err := buf.ReadByte()
+ if err != nil {
return
}
- if ret.StringID == "" {
- if ret.IntID, _, err = cmpbin.ReadInt(buf); err != nil {
- return
- }
- if ret.IntID <= 0 {
+ switch gae.DSPropertyType(typ) {
+ case gae.DSPTString:
+ ret.StringID, _, err = cmpbin.ReadString(buf)
+ case gae.DSPTInt:
+ ret.IntID, _, err = cmpbin.ReadInt(buf)
+ if err == nil && ret.IntID <= 0 {
err = errors.New("helper: decoded key with empty stringID and zero/negative intID")
- return
}
+ default:
+ err = fmt.Errorf("helper: invalid type %s", gae.DSPropertyType(typ))
}
return
}
« no previous file with comments | « no previous file | go/src/infra/gae/libs/gae/helper/serialize_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698