-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder.go
89 lines (71 loc) · 1.45 KB
/
builder.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
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
package fanet
import (
"encoding/hex"
"strconv"
"strings"
)
type sentenceBuilder struct {
builder strings.Builder
}
func newSentenceBuilder(prefix string) *sentenceBuilder {
var b sentenceBuilder
b.builder.WriteString(prefix)
return &b
}
func (b *sentenceBuilder) String() string {
return b.builder.String()
}
func (b *sentenceBuilder) bool(value bool) {
var c byte
if value {
c = '1'
} else {
c = '0'
}
b.builder.WriteByte(c)
}
func (b *sentenceBuilder) bytes(bs []byte) {
b.builder.WriteString(strings.ToUpper(hex.EncodeToString(bs)))
}
func (b *sentenceBuilder) comma() {
b.builder.WriteByte(',')
}
func (b *sentenceBuilder) commaBool(value bool) {
b.comma()
b.bool(value)
}
func (b *sentenceBuilder) commaBytes(bs []byte) {
b.comma()
b.bytes(bs)
}
func (b *sentenceBuilder) commaFloat(f float64) {
b.comma()
b.float(f)
}
func (b *sentenceBuilder) commaHex(i int) {
b.comma()
b.hex(i)
}
func (b *sentenceBuilder) commaInt(i int) {
b.comma()
b.int(i)
}
func (b *sentenceBuilder) commaString(s string) {
b.comma()
b.string(s)
}
func (b *sentenceBuilder) float(f float64) {
b.string(strconv.FormatFloat(f, 'f', -1, 64))
}
func (b *sentenceBuilder) hex(i int) {
b.string(strings.ToUpper(strconv.FormatInt(int64(i), 16)))
}
func (b *sentenceBuilder) int(i int) {
b.string(strconv.Itoa(i))
}
func (b *sentenceBuilder) newline() {
b.builder.WriteByte('\n')
}
func (b *sentenceBuilder) string(s string) {
b.builder.WriteString(s)
}