-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplainstruct.go
48 lines (37 loc) · 867 Bytes
/
plainstruct.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
// Package plainstruct is internal and is used for benchmarking only.
package plainstruct
import "github.com/tigrannajaryan/govariant/variant"
type Variant struct {
typ variant.Type
bytes []byte
str string
i int
f float64
}
func (v *Variant) Type() variant.Type {
return v.typ
}
func IntVariant(v int) Variant {
return Variant{typ: variant.TypeInt, i: v}
}
func StringVariant(v string) Variant {
return Variant{typ: variant.TypeString, str: v}
}
func BytesVariant(v []byte) Variant {
return Variant{typ: variant.TypeBytes, bytes: v}
}
func Float64Variant(v float64) Variant {
return Variant{typ: variant.TypeFloat64, f: v}
}
func (v *Variant) Int() int {
return v.i
}
func (v *Variant) Float64() float64 {
return v.f
}
func (v *Variant) String() (s string) {
return v.str
}
func (v *Variant) Bytes() (b []byte) {
return v.bytes
}