7
7
*/
8
8
export class TVFieldParser {
9
9
static readonly tagDelimiter : string = "=" ;
10
- static readonly fieldDelimiter : string = String . fromCharCode ( 1 ) ;
10
+ static fieldDelimiter : string = String . fromCharCode ( 1 ) ;
11
11
static readonly nullFieldParser : TVFieldParser = new TVFieldParser ( "" , 0 ) ;
12
12
static lengthFieldIds : Array < string > = new Array < string > ( ) ;
13
13
@@ -17,7 +17,7 @@ export class TVFieldParser {
17
17
private valueLength : number = 0 ;
18
18
private nextValueLength : number = 0 ;
19
19
20
- constructor ( str : string , offset : number , fieldDelimiter : string = String . fromCharCode ( 1 ) ) {
20
+ constructor ( str : string , offset : number ) {
21
21
this . str = str ;
22
22
this . tagOffset = offset ;
23
23
}
@@ -135,8 +135,9 @@ export class TVMessageParser implements Iterator<TVFieldParser> {
135
135
// tslint:disable-next-line: max-classes-per-file
136
136
export default class TVFileParser implements Iterator < TVMessageParser > {
137
137
static readonly messageStartDelimiter : string = "8=FIX" ;
138
- static readonly checksumTag : string = String . fromCharCode ( 1 ) + "10=" ;
139
- static readonly fieldDelimiter : string = String . fromCharCode ( 1 ) ;
138
+ static readonly bodyLengthTag : string = "9=" ;
139
+ static readonly checksumTag : string = "10=" ;
140
+ private fieldDelimiter : string = String . fromCharCode ( 1 ) ;
140
141
private messageEndOffset : number = 0 ;
141
142
private str : string = "" ;
142
143
public unprocessedMessages : number = 0 ;
@@ -154,9 +155,17 @@ export default class TVFileParser implements Iterator<TVMessageParser> {
154
155
// find start of the next message using BeginString
155
156
const messageStartOffset : number = this . str . indexOf ( TVFileParser . messageStartDelimiter , this . messageEndOffset ) ;
156
157
if ( messageStartOffset !== - 1 ) {
158
+ const delimiterCharIndex = this . str . indexOf ( TVFileParser . bodyLengthTag , messageStartOffset ) - 1 ;
159
+ // find the character before the second field, tag 9. It is the field delimiter in the log file.
160
+ if ( messageStartOffset !== - 1 ) {
161
+ this . fieldDelimiter = this . str . charAt ( delimiterCharIndex ) ;
162
+ TVFieldParser . fieldDelimiter = this . fieldDelimiter ;
163
+ } else {
164
+ // default to SOH, but give warning
165
+ }
157
166
const checksumOffset : number = this . str . indexOf ( TVFileParser . checksumTag , messageStartOffset ) ;
158
167
if ( checksumOffset !== - 1 ) {
159
- this . messageEndOffset = this . str . indexOf ( TVFileParser . fieldDelimiter , checksumOffset ) ;
168
+ this . messageEndOffset = this . str . indexOf ( this . fieldDelimiter , checksumOffset ) ;
160
169
if ( this . messageEndOffset !== - 1 ) {
161
170
return {
162
171
done : false ,
0 commit comments