/
bit.go
50 lines (41 loc) · 865 Bytes
/
bit.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
package bactract
import (
"fmt"
)
// readBit reads the value for a 1 byte integer column
func readBit(r *tReader, tc TableColumn) (ec ExtractedColumn, err error) {
fn := "readBit"
defSz := 1
if debugFlag {
debOut(fmt.Sprintf("Func %s", fn))
}
// Determine how many bytes to read
ss, err := r.readStoredSize(tc, 1, defSz)
if err != nil {
return
}
// Check for nulls
if ss.isNull {
ec.IsNull = ss.isNull
return
}
// Assert: If not null then the stored size is the default
if ss.byteCount != defSz {
err = fmt.Errorf("%s invalid byteCount (%d vs %d) for column %q", fn, defSz, ss.byteCount, tc.ColName)
return
}
// Read and translate the integer
b, err := r.readBytes(fn, ss.byteCount)
if err != nil {
return
}
if len(b) > 0 {
switch b[len(b)-1] {
case 0x00:
ec.Str = "0"
case 0x01:
ec.Str = "1"
}
}
return
}