1 Star 0 Fork 0

muicx / quickfix

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
tag_value.go 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
Chris Busbey 提交于 2017-10-02 12:40 . message parse edge cases
package quickfix
import (
"bytes"
"fmt"
"strconv"
)
//TagValue is a low-level FIX field abstraction
type TagValue struct {
tag Tag
value []byte
bytes []byte
}
func (tv *TagValue) init(tag Tag, value []byte) {
tv.bytes = strconv.AppendInt(nil, int64(tag), 10)
tv.bytes = append(tv.bytes, []byte("=")...)
tv.bytes = append(tv.bytes, value...)
tv.bytes = append(tv.bytes, []byte("")...)
tv.tag = tag
tv.value = value
}
func (tv *TagValue) parse(rawFieldBytes []byte) error {
sepIndex := bytes.IndexByte(rawFieldBytes, '=')
switch sepIndex {
case -1:
return fmt.Errorf("tagValue.Parse: No '=' in '%s'", rawFieldBytes)
case 0:
return fmt.Errorf("tagValue.Parse: No tag in '%s'", rawFieldBytes)
}
parsedTag, err := atoi(rawFieldBytes[:sepIndex])
if err != nil {
return fmt.Errorf("tagValue.Parse: %s", err.Error())
}
tv.tag = Tag(parsedTag)
n := len(rawFieldBytes)
tv.value = rawFieldBytes[(sepIndex + 1):(n - 1):(n - 1)]
tv.bytes = rawFieldBytes[:n:n]
return nil
}
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)
}
Go
1
https://gitee.com/bradhuang/quickfixgo.git
git@gitee.com:bradhuang/quickfixgo.git
bradhuang
quickfixgo
quickfix
dependabot/go_modules/github.com/mattn/go-sqlite3-1.14.9

搜索帮助