-
Notifications
You must be signed in to change notification settings - Fork 36
/
Float.go
62 lines (51 loc) · 1.09 KB
/
Float.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
57
58
59
60
61
62
package types
import (
"bytes"
"encoding/binary"
"github.com/itering/scale.go/types/scaleBytes"
)
type Float struct {
ScaleDecoder
// bitLength int
// encodedLength int
}
type Float64 struct {
Float
}
func (f *Float64) Init(data scaleBytes.ScaleBytes, option *ScaleDecoderOption) {
// f.bitLength = 64
// f.encodedLength = f.bitLength / 8
f.ScaleDecoder.Init(data, option)
}
func (f *Float64) Process() {
var f64 float64
buf := bytes.NewReader(f.Data.Data)
err := binary.Read(buf, binary.LittleEndian, &f64)
if err != nil {
panic(err)
}
f.Value = f64
}
func (f *Float64) TypeStructString() string {
return "Float64"
}
type Float32 struct {
Float
}
func (f *Float32) Init(data scaleBytes.ScaleBytes, option *ScaleDecoderOption) {
// f.bitLength = 32
// f.encodedLength = f.bitLength / 8
f.ScaleDecoder.Init(data, option)
}
func (f *Float32) Process() {
var f32 float32
buf := bytes.NewReader(f.Data.Data)
err := binary.Read(buf, binary.LittleEndian, &f32)
if err != nil {
panic(err)
}
f.Value = f32
}
func (f *Float32) TypeStructString() string {
return "Float32"
}