@@ -133,18 +133,54 @@ func (s *MessageSuite) TestReBuild() {
133
133
134
134
s .msg .Header .SetField (tagOrigSendingTime , FIXString ("20140515-19:49:56.659" ))
135
135
s .msg .Header .SetField (tagSendingTime , FIXString ("20140615-19:49:56" ))
136
+ s .msg .Header .SetField (tagPossDupFlag , FIXBoolean (true ))
136
137
137
138
rebuildBytes := s .msg .build ()
138
139
139
- expectedBytes := []byte ("8=FIX.4.29=12635 =D34=249= TW52=20140615-19:49:5656=ISLD122=20140515-19:49:56.65911=10021=140=154=155=TSLA60=00010101-00:00:00.00010=128 " )
140
+ expectedBytes := []byte ("8=FIX.4.29=13135 =D34=243=Y49= TW52=20140615-19:49:5656=ISLD122=20140515-19:49:56.65911=10021=140=154=155=TSLA60=00010101-00:00:00.00010=122 " )
140
141
141
- s .True (bytes .Equal (expectedBytes , rebuildBytes ), "Unexpected bytes,\n +%s\n -%s" , rebuildBytes , expectedBytes )
142
+ s .True (bytes .Equal (expectedBytes , rebuildBytes ), "Unexpected bytes,\n +%s\n -%s" , rebuildBytes , expectedBytes )
142
143
143
144
expectedBodyBytes := []byte ("11=10021=140=154=155=TSLA60=00010101-00:00:00.000" )
144
145
145
146
s .True (bytes .Equal (s .msg .bodyBytes , expectedBodyBytes ), "Incorrect body bytes, got %s" , string (s .msg .bodyBytes ))
146
147
}
147
148
149
+ func (s * MessageSuite ) TestReBuildWithRepeatingGroupForResend () {
150
+ // Given the following message with a repeating group
151
+ origHeader := "8=FIXT.1.19=16135=834=349=ISLD52=20240415-03:43:17.92356=TW"
152
+ origBody := "6=1.0011=114=1.0017=131=1.0032=1.0037=138=1.0039=254=155=1150=2151=0.00453=1448=xyzzy447=D452=1"
153
+ origTrailer := "10=014"
154
+ rawMsg := bytes .NewBufferString (origHeader + origBody + origTrailer )
155
+
156
+ // When I reparse the message from the store during a resend request
157
+ s .Nil (ParseMessage (s .msg , rawMsg ))
158
+
159
+ // And I update the headers for resend
160
+ s .msg .Header .SetField (tagOrigSendingTime , FIXString ("20240415-03:43:17.923" ))
161
+ s .msg .Header .SetField (tagSendingTime , FIXString ("20240415-14:41:23.456" ))
162
+ s .msg .Header .SetField (tagPossDupFlag , FIXBoolean (true ))
163
+
164
+ // When I rebuild the message
165
+ rebuildBytes := s .msg .build ()
166
+
167
+ // Then the repeating groups will not be in the correct order in the rebuilt message (note tags 447, 448, 452, 453)
168
+ expectedBytes := []byte ("8=FIXT.1.19=19235=834=343=Y49=ISLD52=20240415-14:41:23.45656=TW122=20240415-03:43:17.9236=1.0011=114=1.0017=131=1.0032=1.0037=138=1.0039=254=155=1150=2151=0.00453=1448=xyzzy447=D452=110=018" )
169
+ s .False (bytes .Equal (expectedBytes , rebuildBytes ), "Unexpected bytes,\n expected: %s\n but was: %s" , expectedBytes , rebuildBytes )
170
+ expectedOutOfOrderBytes := []byte ("8=FIXT.1.19=19235=834=343=Y49=ISLD52=20240415-14:41:23.45656=TW122=20240415-03:43:17.9236=1.0011=114=1.0017=131=1.0032=1.0037=138=1.0039=254=155=1150=2151=0.00447=D448=xyzzy452=1453=110=018" )
171
+ s .True (bytes .Equal (expectedOutOfOrderBytes , rebuildBytes ), "Unexpected bytes,\n expected: %s\n but was: %s" , expectedOutOfOrderBytes , rebuildBytes )
172
+
173
+ // But the bodyBytes will still be correct
174
+ origBodyBytes := []byte (origBody )
175
+ s .True (bytes .Equal (origBodyBytes , s .msg .bodyBytes ), "Incorrect body bytes, \n expected: %s\n but was: %s" , origBodyBytes , s .msg .bodyBytes )
176
+
177
+ // So when I combine the updated header + the original bodyBytes + the as-is trailer
178
+ resendBytes := s .msg .buildWithBodyBytes (s .msg .bodyBytes )
179
+
180
+ // Then the reparsed, rebuilt message will retain the correct ordering of repeating group tags during resend
181
+ s .True (bytes .Equal (expectedBytes , resendBytes ), "Unexpected bytes,\n expected: %s\n but was: %s" , expectedBytes , resendBytes )
182
+ }
183
+
148
184
func (s * MessageSuite ) TestReverseRoute () {
149
185
s .Nil (ParseMessage (s .msg , bytes .NewBufferString ("8=FIX.4.29=17135=D34=249=TW50=KK52=20060102-15:04:0556=ISLD57=AP144=BB115=JCD116=CS128=MG129=CB142=JV143=RY145=BH11=ID21=338=10040=w54=155=INTC60=20060102-15:04:0510=123" )))
150
186
0 commit comments