-
Notifications
You must be signed in to change notification settings - Fork 3
/
int64.go
56 lines (45 loc) · 1.62 KB
/
int64.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
package coltype
import (
"encoding/binary"
"fmt"
"github.com/go-sif/sif"
)
// int64Type is a FixedWidthColumnType which stores a int64 value
type int64Type struct{}
// Size in bytes of a int64Type value
func (c *int64Type) Size() int {
return 8
}
// ToStringT produces a string representation of a value of a int64Type value
func (c *int64Type) ToStringT(v int64) string {
return fmt.Sprintf("%d", v)
}
// ToString produces a string representation of a value of a int64Type value
func (c *int64Type) ToString(v interface{}) string {
return c.ToStringT(v.(int64))
}
// SerializeFixedT defines how values of this type are serialized into raw bytes
func (c *int64Type) SerializeFixedT(v int64, dest []byte) error {
binary.LittleEndian.PutUint64(dest, uint64(v))
return nil
}
// SerializeFixed defines how values of this type are serialized into raw bytes
func (c *int64Type) SerializeFixed(v interface{}, dest []byte) error {
vi, ok := v.(int64)
if !ok {
return fmt.Errorf("value %v is not an int64", vi)
}
return c.SerializeFixedT(vi, dest)
}
// DeserializeT defines how values of this type are deserialized from raw bytes
func (c *int64Type) DeserializeT(sv []byte) (int64, error) {
return int64(binary.LittleEndian.Uint64(sv)), nil
}
// Deserialize defines how values of this type are deserialized from raw bytes
func (c *int64Type) Deserialize(sv []byte) (interface{}, error) {
return c.DeserializeT(sv)
}
// Int64 returns a GenericColumnAccessor for a FixedWidthColumnType which stores an int64 value
func Int64(colName string) sif.GenericColumnAccessor[int64] {
return sif.CreateColumnAccessor[int64](&int64Type{}, colName)
}