| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package memory | 5 package memory |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "fmt" | 9 "fmt" |
| 10 "time" | 10 "time" |
| 11 | 11 |
| 12 ds "github.com/luci/gae/service/datastore" | 12 ds "github.com/luci/gae/service/datastore" |
| 13 "github.com/luci/gae/service/datastore/dskey" |
| 14 "github.com/luci/gae/service/datastore/serialize" |
| 13 "github.com/luci/luci-go/common/cmpbin" | 15 "github.com/luci/luci-go/common/cmpbin" |
| 14 ) | 16 ) |
| 15 | 17 |
| 16 type kv struct{ k, v []byte } | 18 type kv struct{ k, v []byte } |
| 17 | 19 |
| 18 func indx(kind string, orders ...string) *ds.IndexDefinition { | 20 func indx(kind string, orders ...string) *ds.IndexDefinition { |
| 19 ancestor := false | 21 ancestor := false |
| 20 if kind[len(kind)-1] == '!' { | 22 if kind[len(kind)-1] == '!' { |
| 21 ancestor = true | 23 ancestor = true |
| 22 kind = kind[:len(kind)-1] | 24 kind = kind[:len(kind)-1] |
| (...skipping 15 matching lines...) Expand all Loading... |
| 38 propNI = ds.MkPropertyNI | 40 propNI = ds.MkPropertyNI |
| 39 ) | 41 ) |
| 40 | 42 |
| 41 func key(kind string, id interface{}, parent ...ds.Key) ds.Key { | 43 func key(kind string, id interface{}, parent ...ds.Key) ds.Key { |
| 42 p := ds.Key(nil) | 44 p := ds.Key(nil) |
| 43 if len(parent) > 0 { | 45 if len(parent) > 0 { |
| 44 p = parent[0] | 46 p = parent[0] |
| 45 } | 47 } |
| 46 switch x := id.(type) { | 48 switch x := id.(type) { |
| 47 case string: | 49 case string: |
| 48 » » return ds.NewKey(globalAppID, "ns", kind, x, 0, p) | 50 » » return dskey.New(globalAppID, "ns", kind, x, 0, p) |
| 49 case int: | 51 case int: |
| 50 » » return ds.NewKey(globalAppID, "ns", kind, "", int64(x), p) | 52 » » return dskey.New(globalAppID, "ns", kind, "", int64(x), p) |
| 51 default: | 53 default: |
| 52 panic(fmt.Errorf("what the %T: %v", id, id)) | 54 panic(fmt.Errorf("what the %T: %v", id, id)) |
| 53 } | 55 } |
| 54 } | 56 } |
| 55 | 57 |
| 56 // cat is a convenience method for concatenating anything with an underlying | 58 // cat is a convenience method for concatenating anything with an underlying |
| 57 // byte representation into a single []byte. | 59 // byte representation into a single []byte. |
| 58 func cat(bytethings ...interface{}) []byte { | 60 func cat(bytethings ...interface{}) []byte { |
| 59 buf := &bytes.Buffer{} | 61 buf := &bytes.Buffer{} |
| 60 for _, thing := range bytethings { | 62 for _, thing := range bytethings { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 71 cmpbin.WriteFloat64(buf, x) | 73 cmpbin.WriteFloat64(buf, x) |
| 72 case byte: | 74 case byte: |
| 73 buf.WriteByte(x) | 75 buf.WriteByte(x) |
| 74 case ds.PropertyType: | 76 case ds.PropertyType: |
| 75 buf.WriteByte(byte(x)) | 77 buf.WriteByte(byte(x)) |
| 76 case string: | 78 case string: |
| 77 cmpbin.WriteString(buf, x) | 79 cmpbin.WriteString(buf, x) |
| 78 case []byte: | 80 case []byte: |
| 79 buf.Write(x) | 81 buf.Write(x) |
| 80 case time.Time: | 82 case time.Time: |
| 81 » » » ds.WriteTime(buf, x) | 83 » » » serialize.WriteTime(buf, x) |
| 82 case ds.Key: | 84 case ds.Key: |
| 83 » » » ds.WriteKey(buf, ds.WithoutContext, x) | 85 » » » serialize.WriteKey(buf, serialize.WithoutContext, x) |
| 84 case *ds.IndexDefinition: | 86 case *ds.IndexDefinition: |
| 85 » » » x.Write(buf) | 87 » » » serialize.WriteIndexDefinition(buf, *x) |
| 86 default: | 88 default: |
| 87 panic(fmt.Errorf("I don't know how to deal with %T: %#v"
, thing, thing)) | 89 panic(fmt.Errorf("I don't know how to deal with %T: %#v"
, thing, thing)) |
| 88 } | 90 } |
| 89 } | 91 } |
| 90 ret := buf.Bytes() | 92 ret := buf.Bytes() |
| 91 if ret == nil { | 93 if ret == nil { |
| 92 ret = []byte{} | 94 ret = []byte{} |
| 93 } | 95 } |
| 94 return ret | 96 return ret |
| 95 } | 97 } |
| 96 | 98 |
| 97 func icat(bytethings ...interface{}) []byte { | 99 func icat(bytethings ...interface{}) []byte { |
| 98 ret := cat(bytethings...) | 100 ret := cat(bytethings...) |
| 99 for i := range ret { | 101 for i := range ret { |
| 100 ret[i] ^= 0xFF | 102 ret[i] ^= 0xFF |
| 101 } | 103 } |
| 102 return ret | 104 return ret |
| 103 } | 105 } |
| 104 | 106 |
| 105 func sat(bytethings ...interface{}) string { | 107 func sat(bytethings ...interface{}) string { |
| 106 return string(cat(bytethings...)) | 108 return string(cat(bytethings...)) |
| 107 } | 109 } |
| OLD | NEW |