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" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 p := ds.Key(nil) | 44 p := ds.Key(nil) |
45 if len(parent) > 0 { | 45 if len(parent) > 0 { |
46 p = parent[0] | 46 p = parent[0] |
47 } | 47 } |
48 switch x := id.(type) { | 48 switch x := id.(type) { |
49 case string: | 49 case string: |
50 return dskey.New(globalAppID, "ns", kind, x, 0, p) | 50 return dskey.New(globalAppID, "ns", kind, x, 0, p) |
51 case int: | 51 case int: |
52 return dskey.New(globalAppID, "ns", kind, "", int64(x), p) | 52 return dskey.New(globalAppID, "ns", kind, "", int64(x), p) |
53 default: | 53 default: |
54 » » panic(fmt.Errorf("what the %T: %v", id, id)) | 54 » » return dskey.New(globalAppID, "ns", kind, "invalid", 100, p) |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 // cat is a convenience method for concatenating anything with an underlying | 58 // cat is a convenience method for concatenating anything with an underlying |
59 // byte representation into a single []byte. | 59 // byte representation into a single []byte. |
60 func cat(bytethings ...interface{}) []byte { | 60 func cat(bytethings ...interface{}) []byte { |
61 buf := &bytes.Buffer{} | 61 buf := &bytes.Buffer{} |
62 for _, thing := range bytethings { | 62 for _, thing := range bytethings { |
63 switch x := thing.(type) { | 63 switch x := thing.(type) { |
64 case int64: | 64 case int64: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 ret := cat(bytethings...) | 100 ret := cat(bytethings...) |
101 for i := range ret { | 101 for i := range ret { |
102 ret[i] ^= 0xFF | 102 ret[i] ^= 0xFF |
103 } | 103 } |
104 return ret | 104 return ret |
105 } | 105 } |
106 | 106 |
107 func sat(bytethings ...interface{}) string { | 107 func sat(bytethings ...interface{}) string { |
108 return string(cat(bytethings...)) | 108 return string(cat(bytethings...)) |
109 } | 109 } |
OLD | NEW |