publish_<msgName>_Message() Stub

The publish_<msgName>_Message method initializes the message with pub_beginMessage, calls various pub_set<type>Field methods to set field values, and sends or cancels the message.

The API method that publishes the message includes the message name in the form publish_<msgName>_Message. Any characters that are not alphanumeric are changed to underscores. For example, publish_Bond_Quote_Message publishes the Bond Quote message.

You must add error handling to each message processing loop.

Initializing Fields

The publish_<msgName>_Message stub first defines the PUB_SEND_MESSAGE_CONTEXT structure with variables for each field in the message. This structure must be allocated before calling pub_beginMessage().

For example, the stub generated from the Bond Quote sample message definition begins with:

uint16_t publish_Bond_Quote_Message()
{
    PUB_SEND_MESSAGE_CONTEXT ctx; 
    uchar *                  Instrument;
    uint32_t                 Quote_Date;
    int32_t                  Quote_Sequence_Number;
    uint32_t                 Quote_Time_Date;
    uint32_t                 Quote_Time_Time;
    double                   Ask_Price;
    int32_t                  Ask_Size;
    double                   Bid_Price;
    int32_t                  Bid_Size;
    double                   Yield;
    uint16_t                 errorCode;

Starting the Message

Next, the stub calls pub_beginMessage() to begin defining the message.

The stub calls pub_cancelMessage() in each message processing loop to execute if an error is returned.

For example, the Bond Quote stub starts a new message as:

// Parse your message here.

    // Start a new message.
    errorCode = pub_beginMessage( 8, &ctx );
    if( errorCode != ERR_NONE ) {
        pub_cancelMessage( &ctx );
        // Add error handling code.
        return errorCode;
    }

Setting Field Values

The stub adds a pub_set<type>Field() method in a processing loop for each field from the message definition. You must add error handling.

If a field can be null, your code must check for null and call pub_setNullField. Calls to pub_setNullField are commented out in the stub.

For decimal field types, the stub includes all potential API methods for processing the field, with all but pub_setDecimalField commented out. To use a different method, comment out pub_setDecimalField and uncomment the method you want. When choosing a set field method, consider that supported datatypes may have performance or granularity implications.

For example, the Bond Quote stub processes the Bid Price field as:

// Add the Bid Price field to the message.
    errorCode = pub_setDecimalField( &ctx, "Bid Price", Bid_Price );
    // errorCode = pub_setDecimalFieldFromMantissa( &ctx, "Bid Price", Bid_Price_Mantissa, Bid_Price_Exponent );
    // errorCode = pub_setDecimalFieldFromString( &ctx, "Bid Price", Bid_Price_String );
    // errorCode = pub_setNullField( &ctx, "Bid Price" );
    if( errorCode != ERR_NONE ) {
        pub_cancelMessage( &ctx );
        // Add error handling code.
        return errorCode;
    }

Sending the Message

The stub calls pub_sendMessage to send the message, or pub_cancelMessage upon error.

Related concepts
Example: Building a Market Data Message
Related tasks
Developing with the publish_<msgName>_Message() Stub
Related reference
Supported Datatypes for Message Flow