objectcomputing / mFAST

A FAST (FIX Adapted for STreaming) encoder/decoder
http://objectcomputing.github.io/mFAST
BSD 3-Clause "New" or "Revised" License
220 stars 114 forks source link

How to copy message by _cref? #37

Closed IkSin88 closed 9 years ago

IkSin88 commented 9 years ago
#include <mfast.h>
#include <iostream>

#include "scheme.h"

int main(int argc, char *argv[])
{
    // Create message
    scheme::_0 msg;
    scheme::_0_mref msg_mref = msg.mref();
    scheme::_0_cref msg_cref = msg.cref();

    // Fill message fields
    msg_mref.set_SendingTime().as(20150701121211999);
    msg_mref.set_MsgSeqNum().as(399);

    // Copy message
    mfast::message_type copied_msg(msg_cref, mfast::malloc_allocator::instance());
    scheme::_0_cref copied_msg_cref = static_cast< scheme::_0_cref >(copied_msg.cref());

    // Print SendingTime
    std::cout << "MSG SendingTime = " << msg_cref.get_SendingTime().value() << std::endl;
    std::cout << "Copied MSG SendingTime = " << copied_msg_cref.get_SendingTime().value() << std::endl;

    return 0;
}

Output: MSG SendingTime = 20150701121211999 Copied MSG SendingTime = 3472328298477784671

How to copy mfast messages from his _cref class? How i can store mfast messages in containers?

huangminghuang commented 9 years ago

You didn't give me the scheme file so I cannot test it directly. However, your code looks legitimate to me. You can checkout the copy-message-test branch and run examples/message_printer to see if it works correctly for you.

IkSin88 commented 9 years ago

scheme.xml

<?xml version="1.0" encoding="UTF-8" ?>
<templates xmlns="http://www.fixprotocol.org/ns/fast/td/1.1">
<!-- Heartbeat -->
    <template name="0" id="2108" xmlns="http://www.fixprotocol.org/ns/fast/td/1.1">
        <string name="MessageType" id="35"><constant value="0" /></string>
        <string name="BeginString" id="8"><constant value="FIXT.1.1"/></string>
        <string name="SenderCompID" id="49"><constant value="MOEX"/></string>
        <uInt32 name="MsgSeqNum" id="34"></uInt32>
        <uInt64 name="SendingTime" id="52"></uInt64>
    </template>
</templates>

examples/message_printer from copy-message-test branch works fine: BeginString: FIX4.4 MessageType: X SenderCompID: MsgSeqNum: 0 MDEntries: [0]: MDUpdateAction: 1 MDEntryType: abcd Symbol: AAPL SecurityType: Stock MDEntryPx: 110^2 MDEntrySize: 310^4 NumberOfOrders: 100 QuoteCondition: TradeCondition:

my example with scheme.xml still don't works correctly: MSG SendingTime = 20150701121211999 Copied MSG SendingTime = 3472328298477784671

huangminghuang commented 9 years ago

I think this is an issue only for 32 bits build. Try the commit 7e2d681b97c8b87aa9a0a39ad53bca98b8295d50 to see it works for you.

IkSin88 commented 9 years ago

Thanks! That works for me!