Example #1
0
static void fix_message_unparse(struct fix_message *self)
{
	struct fix_field sender_comp_id;
	struct fix_field target_comp_id;
	struct fix_field begin_string;
	struct fix_field sending_time;
	struct fix_field body_length;
	struct fix_field msg_seq_num;
	struct fix_field check_sum;
	struct fix_field msg_type;
	unsigned long cksum;
	char fmt[64], buf[64];
	struct timeval tv;
	struct tm *tm;
	int i;

	gettimeofday(&tv, NULL);
	tm = gmtime(&tv.tv_sec);
	assert(tm != NULL);

	/* YYYYMMDD-HH:MM:SS.sss */
	strftime(fmt, sizeof fmt, "%Y%m%d-%H:%M:%S", tm);
	snprintf(buf, sizeof buf, "%s.%03ld", fmt, (long)tv.tv_usec / 1000);

	/* standard header */
	msg_type	= FIX_STRING_FIELD(MsgType, self->msg_type);
	sender_comp_id	= FIX_STRING_FIELD(SenderCompID, self->sender_comp_id);
	target_comp_id	= FIX_STRING_FIELD(TargetCompID, self->target_comp_id);
	msg_seq_num	= FIX_INT_FIELD   (MsgSeqNum, self->msg_seq_num);
	sending_time	= FIX_STRING_FIELD(SendingTime, buf);

	/* body */
	fix_field_unparse(&msg_type, self->body_buf);
	fix_field_unparse(&sender_comp_id, self->body_buf);
	fix_field_unparse(&target_comp_id, self->body_buf);
	fix_field_unparse(&msg_seq_num, self->body_buf);
	fix_field_unparse(&sending_time, self->body_buf);

	for (i = 0; i < self->nr_fields; i++)
		fix_field_unparse(&self->fields[i], self->body_buf);

	/* head */
	begin_string	= FIX_STRING_FIELD(BeginString, self->begin_string);
	body_length	= FIX_INT_FIELD(BodyLength, buffer_size(self->body_buf));

	fix_field_unparse(&begin_string, self->head_buf);
	fix_field_unparse(&body_length, self->head_buf);

	/* trailer */
	cksum		= buffer_sum(self->head_buf) + buffer_sum(self->body_buf);
	check_sum	= FIX_CHECKSUM_FIELD(CheckSum, cksum % 256);
	fix_field_unparse(&check_sum, self->body_buf);
}
Example #2
0
void fix_message_unparse(struct fix_message *self)
{
    struct fix_field sender_comp_id;
    struct fix_field target_comp_id;
    struct fix_field begin_string;
    struct fix_field sending_time;
    struct fix_field body_length;
    struct fix_field msg_seq_num;
    struct fix_field check_sum;
    struct fix_field msg_type;
    unsigned long cksum;
    char buf[64];
    int i;

    TRACE(LIBTRADING_FIX_MESSAGE_UNPARSE(self));

    strncpy(buf, self->str_now, sizeof(buf));

    /* standard header */
    msg_type	= (self->type != FIX_MSG_TYPE_UNKNOWN) ?
                  FIX_STRING_FIELD(MsgType, fix_msg_types[self->type]) :
                  FIX_STRING_FIELD(MsgType, self->msg_type);
    sender_comp_id	= FIX_STRING_FIELD(SenderCompID, self->sender_comp_id);
    target_comp_id	= FIX_STRING_FIELD(TargetCompID, self->target_comp_id);
    msg_seq_num	= FIX_INT_FIELD   (MsgSeqNum, self->msg_seq_num);
    sending_time	= FIX_STRING_FIELD(SendingTime, buf);

    /* body */
    fix_field_unparse(&msg_type, self->body_buf);
    fix_field_unparse(&sender_comp_id, self->body_buf);
    fix_field_unparse(&target_comp_id, self->body_buf);
    fix_field_unparse(&msg_seq_num, self->body_buf);
    fix_field_unparse(&sending_time, self->body_buf);

    for (i = 0; i < self->nr_fields; i++)
        fix_field_unparse(&self->fields[i], self->body_buf);

    /* head */
    begin_string	= FIX_STRING_FIELD(BeginString, self->begin_string);
    body_length	= FIX_INT_FIELD(BodyLength, buffer_size(self->body_buf));

    fix_field_unparse(&begin_string, self->head_buf);
    fix_field_unparse(&body_length, self->head_buf);

    /* trailer */
    cksum		= buffer_sum(self->head_buf) + buffer_sum(self->body_buf);
    check_sum	= FIX_CHECKSUM_FIELD(CheckSum, cksum % 256);
    fix_field_unparse(&check_sum, self->body_buf);

    TRACE(LIBTRADING_FIX_MESSAGE_UNPARSE_RET());
}