maxim2266/FullFIX

Having Trouble Parsing a single Message

harshhacks opened this issue · 1 comments

I tried to write a toy program that uses the library to parse a single FIX message.

Included "fix.h" and FIX44.h (which got created from the complie-spec).

Created a parser_context structure:

typedef struct
{
fix_parser* parser;

}parser_context;

Wrote a simple parsing function:

int parse(parser_context* context, const void* buff, unsigned n)
{
// const fix_parser_result* res =get_first_fix_message(context->parser, buff, n);
// printf("%d", res->msg_type_code);
for(const fix_parser_result* res =get_first_fix_message(context->parser, buff, n);
res != NULL;
res = get_next_fix_message(context->parser))
{printf("Entered Loop");
if(res->error.code == FE_OK)
printf("Parsing Successful");
else
printf(CParsing Failed");

}
free_fix_parser(context-> parser);
return 1;

}

Instantiated the context in main:

int main()
{
parser_context* f1 = malloc(sizeof(parser_context));
f1->parser = create_FIX44_parser(); //This constructor was created by compile-spec

char buffer[1000];

printf("Enter the FIX message");
fgets(buffer, 1000, stdin);
parse(f1, buffer, strlen(buffer));
return 0;

}

In the standard input, I provided the following FIX message:

8=FIX.4.4\x019=178\x0135=D\x0149=SenderCompID\x0156=TargetCompID\x0134=1122\x0152=20210907-09:30:00.000\x0111=12345\x0121=1\x0155=MSFT\x0154=1\x0160=20210907-09:30:00.000\x0138=100\x0140=2\x0144=300.00\x0159=0\x0110=128\x01

The program never entered the for loop in the parse function.

To check what was happening, I uncommented the first two lines in the parse function to see what the parser was returning.

res->msg_type_code and even trying to print the error code both returned seg faults.

Is there any modification I should be making to my implementation?

Thanks!

I am afraid I cannot debug the code for you. I would suggest you to look at the examples in the documentation and/or parser test cases.