forked from sfproductlabs/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathudt.go
More file actions
89 lines (83 loc) · 3.4 KB
/
udt.go
File metadata and controls
89 lines (83 loc) · 3.4 KB
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
/*===----------- udt.go - udt for cassandra data types -------------===
*
*
* This file is licensed under the Apache 2 License. See LICENSE for details.
*
* Copyright (c) 2018 Andrew Grosser. All Rights Reserved.
*
* `...
* yNMMh`
* dMMMh`
* dMMMh`
* dMMMh`
* dMMMd`
* dMMMm.
* dMMMm.
* dMMMm. /hdy.
* ohs+` yMMMd. yMMM-
* .mMMm. yMMMm. oMMM/
* :MMMd` sMMMN. oMMMo
* +MMMd` oMMMN. oMMMy
* sMMMd` /MMMN. oMMMh
* sMMMd` /MMMN- oMMMd
* oMMMd` :NMMM- oMMMd
* /MMMd` -NMMM- oMMMm
* :MMMd` .mMMM- oMMMm`
* -NMMm. `mMMM: oMMMm`
* .mMMm. dMMM/ +MMMm`
* `hMMm. hMMM/ /MMMm`
* yMMm. yMMM/ /MMMm`
* oMMm. oMMMo -MMMN.
* +MMm. +MMMo .MMMN-
* +MMm. /MMMo .NMMN-
* ` +MMm. -MMMs .mMMN: `.-.
* /hys:` +MMN- -NMMy `hMMN: .yNNy
* :NMMMy` sMMM/ .NMMy yMMM+-dMMMo
* +NMMMh-hMMMo .mMMy +MMMmNMMMh`
* /dMMMNNMMMs .dMMd -MMMMMNm+`
* .+mMMMMMN: .mMMd `NMNmh/`
* `/yhhy: `dMMd /+:`
* `hMMm`
* `hMMm.
* .mMMm:
* :MMMd-
* -NMMh.
* ./:.
*
*===----------------------------------------------------------------------===
*/
package main
import (
"fmt"
"github.com/gocql/gocql"
)
type geo_point struct {
Lat float64 `cql:"lat"`
Lon float64 `cql:"lon"`
}
type viewport struct {
W int64 `cql:"w"`
H int64 `cql:"h"`
}
// NOTE: due to current implementation details it is not currently possible to use
// a pointer receiver type for the UDTMarshaler interface to handle UDT's
func (p geo_point) MarshalUDT(name string, info gocql.TypeInfo) ([]byte, error) {
switch name {
case "lat":
return gocql.Marshal(info, p.Lat)
case "lon":
return gocql.Marshal(info, p.Lon)
default:
return nil, fmt.Errorf("unknown column for position: %q", name)
}
}
func (p *geo_point) UnmarshalUDT(name string, info gocql.TypeInfo, data []byte) error {
switch name {
case "lat":
return gocql.Unmarshal(info, data, &p.Lat)
case "lon":
return gocql.Unmarshal(info, data, &p.Lon)
default:
return fmt.Errorf("unknown column for position: %q", name)
}
}