OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package unsafe | |
6 | |
7 import ( | |
8 "time" | |
9 | |
10 "unsafe" | |
11 | |
12 "appengine/memcache" | |
13 ) | |
14 | |
15 // Item is duplicated from appengine/memcache. | |
16 type Item struct { | |
17 Key string | |
18 Value []byte | |
19 Object interface{} | |
20 Flags uint32 | |
21 Expiration time.Duration | |
22 CasID uint64 | |
23 } | |
24 | |
25 func init() { | |
26 // we can't actually refer to casID by name, but we can refer to everyth
ing | |
27 // else, and ensure that everything lines up. This should catch an api c
hange, | |
28 // but wouldn't catch something like uint64 -> int64. | |
29 if unsafe.Sizeof(memcache.Item{}) != unsafe.Sizeof(Item{}) { | |
30 panic("memcache.Item and Item mismatch sizes") | |
31 } | |
32 if unsafe.Offsetof(memcache.Item{}.Key) != unsafe.Offsetof(Item{}.Key) { | |
33 panic("memcache.Item and Item mismatch Key") | |
34 } | |
35 if unsafe.Offsetof(memcache.Item{}.Value) != unsafe.Offsetof(Item{}.Valu
e) { | |
36 panic("memcache.Item and Item mismatch Value") | |
37 } | |
38 if unsafe.Offsetof(memcache.Item{}.Object) != unsafe.Offsetof(Item{}.Obj
ect) { | |
39 panic("memcache.Item and Item mismatch Object") | |
40 } | |
41 if unsafe.Offsetof(memcache.Item{}.Flags) != unsafe.Offsetof(Item{}.Flag
s) { | |
42 panic("memcache.Item and Item mismatch Flags") | |
43 } | |
44 if unsafe.Offsetof(memcache.Item{}.Expiration) != unsafe.Offsetof(Item{}
.Expiration) { | |
45 panic("memcache.Item and Item mismatch Expiration") | |
46 } | |
47 } | |
48 | |
49 // MCSetCasID sets the private .casID field of memcache.Item. | |
50 func MCSetCasID(i *memcache.Item, val uint64) { | |
51 mci := (*Item)(unsafe.Pointer(i)) | |
52 mci.CasID = val | |
53 } | |
54 | |
55 // MCGetCasID retrieves the private .casID field of memcache.Item. | |
56 func MCGetCasID(i *memcache.Item) uint64 { | |
57 return (*Item)(unsafe.Pointer(i)).CasID | |
58 } | |
OLD | NEW |