@@ -3,16 +3,77 @@ package quickfix
33import (
44 "bytes"
55 "fmt"
6+ "math"
67 "time"
78
89 "github.com/quickfixgo/quickfix/enum"
910)
1011
12+ //Header is first section of a FIX Message
13+ type Header struct { FieldMap }
14+
15+ //Init initializes the Header instance
16+ func (h * Header ) Init () {
17+ //in the message header, the first 3 tags in the message header must be 8,9,35
18+ h .initWithOrdering (func (i , j Tag ) bool {
19+ var ordering = func (t Tag ) uint32 {
20+ switch t {
21+ case tagBeginString :
22+ return 1
23+ case tagBodyLength :
24+ return 2
25+ case tagMsgType :
26+ return 3
27+ }
28+
29+ return math .MaxUint32
30+ }
31+
32+ orderi := ordering (i )
33+ orderj := ordering (j )
34+
35+ switch {
36+ case orderi < orderj :
37+ return true
38+ case orderi > orderj :
39+ return false
40+ }
41+
42+ return i < j
43+ })
44+ }
45+
46+ //Body is the primary application section of a FIX message
47+ type Body struct { FieldMap }
48+
49+ //Init initializes the FIX message
50+ func (b * Body ) Init () {
51+ b .init ()
52+ }
53+
54+ //Trailer is the last section of a FIX message
55+ type Trailer struct { FieldMap }
56+
57+ //Init initializes the FIX message
58+ func (t * Trailer ) Init () {
59+ // In the trailer, CheckSum (tag 10) must be last
60+ t .initWithOrdering (func (i , j Tag ) bool {
61+ switch {
62+ case i == tagCheckSum :
63+ return false
64+ case j == tagCheckSum :
65+ return true
66+ }
67+
68+ return i < j
69+ })
70+ }
71+
1172//Message is a FIX Message abstraction.
1273type Message struct {
13- Header FieldMap
14- Trailer FieldMap
15- Body FieldMap
74+ Header Header
75+ Trailer Trailer
76+ Body Body
1677
1778 //ReceiveTime is the time that this message was read from the socket connection
1879 ReceiveTime time.Time
@@ -38,15 +99,11 @@ func (e parseError) Error() string { return fmt.Sprintf("error parsing message:
3899
39100//NewMessage returns a newly initialized Message instance
40101func NewMessage () (m Message ) {
41- m .Init ()
42- return
43- }
102+ m .Header . Init ()
103+ m . Body . Init ()
104+ m . Trailer . Init ()
44105
45- //Init initializes the Message instance
46- func (m * Message ) Init () {
47- m .Header .init (headerFieldOrder )
48- m .Body .init (normalFieldOrder )
49- m .Trailer .init (trailerFieldOrder )
106+ return
50107}
51108
52109//ParseMessage constructs a Message from a byte slice wrapping a FIX message.
0 commit comments