@@ -82,7 +82,7 @@ type Message struct {
8282 //ReceiveTime is the time that this message was read from the socket connection
8383 ReceiveTime time.Time
8484
85- rawMessage [] byte
85+ rawMessage * bytes. Buffer
8686
8787 //slice of Bytes corresponding to the message body
8888 bodyBytes []byte
@@ -114,15 +114,17 @@ func NewMessage() (m Message) {
114114}
115115
116116//ParseMessage constructs a Message from a byte slice wrapping a FIX message.
117- func ParseMessage (msg * Message , rawMessage [] byte ) (err error ) {
117+ func ParseMessage (msg * Message , rawMessage * bytes. Buffer ) (err error ) {
118118 msg .Header .Clear ()
119119 msg .Body .Clear ()
120120 msg .Trailer .Clear ()
121121 msg .rawMessage = rawMessage
122122
123+ rawBytes := rawMessage .Bytes ()
124+
123125 //allocate fields in one chunk
124126 fieldCount := 0
125- for _ , b := range rawMessage {
127+ for _ , b := range rawBytes {
126128 if b == '\001' {
127129 fieldCount ++
128130 }
@@ -137,23 +139,23 @@ func ParseMessage(msg *Message, rawMessage []byte) (err error) {
137139 fieldIndex := 0
138140
139141 //message must start with begin string, body length, msg type
140- if rawMessage , err = extractSpecificField (& msg .fields [fieldIndex ], tagBeginString , rawMessage ); err != nil {
142+ if rawBytes , err = extractSpecificField (& msg .fields [fieldIndex ], tagBeginString , rawBytes ); err != nil {
141143 return
142144 }
143145
144146 msg .Header .tagLookup [msg .fields [fieldIndex ].tag ] = msg .fields [fieldIndex : fieldIndex + 1 ]
145147 fieldIndex ++
146148
147149 parsedFieldBytes := & msg .fields [fieldIndex ]
148- if rawMessage , err = extractSpecificField (parsedFieldBytes , tagBodyLength , rawMessage ); err != nil {
150+ if rawBytes , err = extractSpecificField (parsedFieldBytes , tagBodyLength , rawBytes ); err != nil {
149151 return
150152 }
151153
152154 msg .Header .tagLookup [parsedFieldBytes .tag ] = msg .fields [fieldIndex : fieldIndex + 1 ]
153155 fieldIndex ++
154156
155157 parsedFieldBytes = & msg .fields [fieldIndex ]
156- if rawMessage , err = extractSpecificField (parsedFieldBytes , tagMsgType , rawMessage ); err != nil {
158+ if rawBytes , err = extractSpecificField (parsedFieldBytes , tagMsgType , rawBytes ); err != nil {
157159 return
158160 }
159161
@@ -164,7 +166,7 @@ func ParseMessage(msg *Message, rawMessage []byte) (err error) {
164166 foundBody := false
165167 for {
166168 parsedFieldBytes = & msg .fields [fieldIndex ]
167- rawMessage , err = extractField (parsedFieldBytes , rawMessage )
169+ rawBytes , err = extractField (parsedFieldBytes , rawBytes )
168170 if err != nil {
169171 return
170172 }
@@ -176,15 +178,15 @@ func ParseMessage(msg *Message, rawMessage []byte) (err error) {
176178 msg .Trailer .tagLookup [parsedFieldBytes .tag ] = msg .fields [fieldIndex : fieldIndex + 1 ]
177179 default :
178180 foundBody = true
179- trailerBytes = rawMessage
181+ trailerBytes = rawBytes
180182 msg .Body .tagLookup [parsedFieldBytes .tag ] = msg .fields [fieldIndex : fieldIndex + 1 ]
181183 }
182184 if parsedFieldBytes .tag == tagCheckSum {
183185 break
184186 }
185187
186188 if ! foundBody {
187- msg .bodyBytes = rawMessage
189+ msg .bodyBytes = rawBytes
188190 }
189191
190192 fieldIndex ++
@@ -296,7 +298,7 @@ func extractField(parsedFieldBytes *TagValue, buffer []byte) (remBytes []byte, e
296298
297299func (m Message ) String () string {
298300 if m .rawMessage != nil {
299- return string ( m .rawMessage )
301+ return m .rawMessage . String ( )
300302 }
301303
302304 return string (m .build ())
0 commit comments