-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (53 loc) · 1.19 KB
/
main.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
package main
import (
"bytes"
"fmt"
"log"
"os"
"text/tabwriter"
"bufio"
"github.com/quickfixgo/quickfix"
"github.com/quickfixgo/quickfix/datadictionary"
)
func main() {
dd, err := datadictionary.Parse("FIX41.xml")
if err != nil {
log.Fatal(err)
}
f, err := os.Open("fix.msg")
if err != nil {
log.Fatal(err)
}
fb := bufio.NewReader(f)
for line, err := fb.ReadBytes(byte('\n')); err == nil; line, err = fb.ReadBytes(byte('\n')) {
b := bytes.NewBuffer(line)
m := quickfix.NewMessage()
err = nil
err = quickfix.ParseMessageWithDataDictionary(m, b, dd, dd)
if err != nil {
log.Println(err)
return
}
tw := tabwriter.NewWriter(os.Stdout, 1, 1, 1, '.', 0)
for _, t := range m.Body.Tags() {
val, err := m.Body.GetBytes(t)
if err != nil {
log.Println(err)
continue
}
d, ok := dd.FieldTypeByTag[int(t)]
if !ok {
log.Println(t, "not found in dictioary")
}
strval := string(val) + "\t"
if len(d.Enums) > 0 {
if e, ok := d.Enums[string(val)]; ok {
strval = e.Value + "\t(" + e.Description + ")"
}
}
fmt.Fprintf(tw, "%s\t(%d)\t=\t%s\n", d.Name(), t, strval)
}
tw.Flush()
fmt.Println("----------------------------")
}
}