-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathstypes.go
106 lines (93 loc) · 1.61 KB
/
stypes.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2017 The go-sqlite Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package sqlite3
import (
"fmt"
)
// SerialType represents SQLite types on disk
type SerialType int
const (
StNull SerialType = iota
StInt8
StInt16
StInt24
StInt32
StInt48
StInt64
StFloat
StC0
StC1
StBlob SerialType = 12
StText = 13
)
func (st SerialType) String() string {
switch st {
case StNull:
return "StNull"
case StInt8:
return "StInt8"
case StInt16:
return "StInt16"
case StInt24:
return "StInt24"
case StInt32:
return "StInt32"
case StInt48:
return "StInt48"
case StInt64:
return "StInt64"
case StFloat:
return "StFloat"
case StC0:
return "StC0"
case StC1:
return "StC1"
}
if st.IsBlob() {
sz := int(st-12) / 2
return fmt.Sprintf("StBlob(%d)", sz)
}
if st.IsText() {
sz := int(st-13) / 2
return fmt.Sprintf("StText(%d)", sz)
}
panic("unreachable")
}
func (st SerialType) IsBlob() bool {
return st >= 12 && st&1 == 0
}
func (st SerialType) IsText() bool {
return st >= 13 && st&1 == 1
}
// NBytes returns the number of bytes on disk for this SerialType
// NBytes returns -1 if the SerialType is invalid.
func (st SerialType) NBytes() int {
switch st {
case StNull:
return 0
case StInt8:
return 1
case StInt16:
return 2
case StInt24:
return 3
case StInt32:
return 4
case StInt48:
return 6
case StInt64:
return 8
case StFloat:
return 8
case StC0, StC1:
return 0
}
if st.IsBlob() {
return int(st-12) / 2
}
if st.IsText() {
return int(st-13) / 2
}
return -1
}