-
Notifications
You must be signed in to change notification settings - Fork 30
/
value_object.go
50 lines (42 loc) · 1.08 KB
/
value_object.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 vs
import (
"github.com/chrislusf/vasto/pb"
"github.com/chrislusf/vasto/util"
)
type ValueObject struct {
valueType pb.OpAndDataType
value []byte
}
// Value creates a ValueObject with a specific type
func Value(value []byte, valueType pb.OpAndDataType) *ValueObject {
return &ValueObject{
value: value,
valueType: valueType,
}
}
// BytesValue creates a ValueObject with a bytes value
func BytesValue(value []byte) *ValueObject {
return &ValueObject{
value: value,
valueType: pb.OpAndDataType_BYTES,
}
}
// Float64Value creates a ValueObject with a float64 value
func Float64Value(value float64) *ValueObject {
return &ValueObject{
value: util.Float64ToBytes(value),
valueType: pb.OpAndDataType_FLOAT64,
}
}
// GetValue returns the value bytes
func (v *ValueObject) GetValue() []byte {
return v.value
}
// GetFloat64 returns the value float64
func (v *ValueObject) GetFloat64() float64 {
return util.BytesToFloat64(v.value)
}
// GetValueType returns the data type of the value
func (v *ValueObject) GetValueType() pb.OpAndDataType {
return v.valueType
}