forked from cedar-policy/cedar-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlong.go
43 lines (34 loc) · 930 Bytes
/
long.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
package types
import (
"fmt"
"github.com/cedar-policy/cedar-go/internal"
)
// A Long is a whole number without decimals that can range from -9223372036854775808 to 9223372036854775807.
type Long int64
func (a Long) Equal(bi Value) bool {
b, ok := bi.(Long)
return ok && a == b
}
func (a Long) LessThan(bi Value) (bool, error) {
b, ok := bi.(Long)
if !ok {
return false, internal.ErrNotComparable
}
return a < b, nil
}
func (a Long) LessThanOrEqual(bi Value) (bool, error) {
b, ok := bi.(Long)
if !ok {
return false, internal.ErrNotComparable
}
return a <= b, nil
}
// String produces a string representation of the Long, e.g. `42`.
func (v Long) String() string { return fmt.Sprint(int64(v)) }
// MarshalCedar produces a valid MarshalCedar language representation of the Long, e.g. `42`.
func (v Long) MarshalCedar() []byte {
return []byte(v.String())
}
func (v Long) hash() uint64 {
return uint64(v)
}