/
tbl-neworder.go
73 lines (66 loc) · 1.5 KB
/
tbl-neworder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"github.com/mit-pdos/vmvcc/vmvcc"
)
func GetNewOrder(txn *vmvcc.Txn, oid uint32, did uint8, wid uint8) (*NewOrder, bool) {
x := &NewOrder {
NO_O_ID : oid,
NO_D_ID : did,
NO_W_ID : wid,
}
gkey := x.gkey()
found := readtbl(txn, gkey, x)
return x, found
}
/**
* Table mutator methods.
*/
func InsertNewOrder(txn *vmvcc.Txn, oid uint32, did uint8, wid uint8) {
x := &NewOrder {
NO_O_ID : oid,
NO_D_ID : did,
NO_W_ID : wid,
}
gkey := x.gkey()
writetbl(txn, gkey, x)
}
func DeleteNewOrder(txn *vmvcc.Txn, oid uint32, did uint8, wid uint8) {
x := &NewOrder {
NO_O_ID : oid,
NO_D_ID : did,
NO_W_ID : wid,
}
gkey := x.gkey()
deletetbl(txn, gkey)
}
/**
* Convert primary keys of table NewOrder to a global key.
* Used by all both TableRead and TableWrite.
*/
func (x *NewOrder) gkey() uint64 {
var gkey uint64 = uint64(x.NO_O_ID)
gkey = gkey << 8 + uint64(x.NO_D_ID)
gkey = gkey << 8 + uint64(x.NO_W_ID)
gkey += TBLID_NEWORDER
return gkey
}
/**
* Encode a NewOrder record to an opaque string.
* Used by TableWrite.
*/
func (x *NewOrder) encode() string {
buf := make([]byte, X_NO_LEN)
encodeU32(buf, x.NO_O_ID, X_NO_O_ID)
encodeU8(buf, x.NO_D_ID, X_NO_D_ID)
encodeU8(buf, x.NO_W_ID, X_NO_W_ID)
return bytesToString(buf)
}
/**
* Decode an opaque string to a NewOrder record.
* Used by TableRead.
*/
func (x *NewOrder) decode(opaque string) {
decodeU32(&x.NO_O_ID, opaque, X_NO_O_ID)
decodeU8(&x.NO_D_ID, opaque, X_NO_D_ID)
decodeU8(&x.NO_W_ID, opaque, X_NO_W_ID)
}