forked from quickfixgo/quickfix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag_value.go
69 lines (53 loc) · 1.16 KB
/
tag_value.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
package quickfix
import (
"bytes"
"fmt"
"strconv"
)
//tagValue is a low-level FIX field abstraction
type tagValue struct {
Tag
Value []byte
bytes []byte
}
//tagValues is a slice of tagValue
type tagValues []tagValue
func (tv *tagValue) init(tag Tag, value []byte) {
var buf bytes.Buffer
buf.WriteString(strconv.Itoa(int(tag)))
buf.WriteString("=")
buf.Write(value)
buf.WriteString("")
tv.Tag = tag
tv.bytes = buf.Bytes()
tv.Value = value
}
func (tv *tagValue) parse(rawFieldBytes []byte) (err error) {
sepIndex := bytes.IndexByte(rawFieldBytes, '=')
if sepIndex == -1 {
err = fmt.Errorf("tagValue.Parse: No '=' in '%s'", rawFieldBytes)
return
}
parsedTag, err := atoi(rawFieldBytes[:sepIndex])
if err != nil {
err = fmt.Errorf("tagValue.Parse: %s", err.Error())
return
}
tv.Tag = Tag(parsedTag)
tv.Value = rawFieldBytes[(sepIndex + 1):(len(rawFieldBytes) - 1)]
tv.bytes = rawFieldBytes
return
}
func (tv tagValue) String() string {
return string(tv.bytes)
}
func (tv tagValue) total() int {
total := 0
for _, b := range []byte(tv.bytes) {
total += int(b)
}
return total
}
func (tv tagValue) length() int {
return len(tv.bytes)
}