Publisher API Stubs Example

This example shows the complete stub generated from the Bond History message definition in the sample RAP Messages model.

BOND_HISTORY.c Publisher API Stub

typedef enum {FALSE=0, TRUE} bool;
#define true 1
#define false 0

#include <stdint.h>
#include "publisher_api.h"
#include "publisher_errors.h"

uint16_t publish_Bond_Quote_Message();

int main( int argc, char ** argv ) 
{
    PUB_STARTUP startup_settings;
    uint16_t    errorCode;

    // Set the startup_settings
    errorCode = pub_initialize( &startup_settings );
    if( errorCode != ERR_NONE ) {
        // Add error handling code.
    }

    errorCode = publish_Bond_Quote_Message();
    if( errorCode != ERR_NONE ) {
        // Add error handling code.
    }

    errorCode = pub_shutdown( true );
    if( errorCode != ERR_NONE ) {
        // Add error handling code.	
    }
    
    return 0;
}

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;
    
    // 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;
    }
    
    // Add the Instrument field to the message.
    errorCode = pub_setStringField( &ctx, "Instrument", Instrument );
    // errorCode = pub_setNullField( &ctx, "Instrument" );
    if( errorCode != ERR_NONE ) {
        pub_cancelMessage( &ctx );
        // Add error handling code.
        return errorCode;
    }
    
    // Add the Quote Date field to the message.
    errorCode = pub_setDateField( &ctx, "Quote Date", Quote_Date );
    // errorCode = pub_setNullField( &ctx, "Quote Date" );
    if( errorCode != ERR_NONE ) {
        pub_cancelMessage( &ctx );
        // Add error handling code.
        return errorCode;
    }
    
    // Add the Quote Sequence Number field to the message.
    errorCode = pub_setInt32Field( &ctx, "Quote Sequence Number", Quote_Sequence_Number );
    // errorCode = pub_setNullField( &ctx, "Quote Sequence Number" );
    if( errorCode != ERR_NONE ) {
        pub_cancelMessage( &ctx );
        // Add error handling code.
        return errorCode;
    }
    
    // Add the Quote Time field to the message.
    errorCode = pub_setDateTimeField( &ctx, "Quote Time", Quote_Time_Date, Quote_Time_Time );
    // errorCode = pub_setNullField( &ctx, "Quote Time" );
    if( errorCode != ERR_NONE ) {
        pub_cancelMessage( &ctx );
        // Add error handling code.
        return errorCode;
    }
    
    // Add the Ask Price field to the message.
    errorCode = pub_setDecimalField( &ctx, "Ask Price", Ask_Price );
    // errorCode = pub_setDecimalFieldFromMantissa( &ctx, "Ask Price", Ask_Price_Mantissa, Ask_Price_Exponent );
    // errorCode = pub_setDecimalFieldFromString( &ctx, "Ask Price", Ask_Price_String );
    // errorCode = pub_setNullField( &ctx, "Ask Price" );
    if( errorCode != ERR_NONE ) {
        pub_cancelMessage( &ctx );
        // Add error handling code.
        return errorCode;
    }
    
    // Add the Ask Size field to the message.
    errorCode = pub_setInt32Field( &ctx, "Ask Size", Ask_Size );
    // errorCode = pub_setNullField( &ctx, "Ask Size" );
    if( errorCode != ERR_NONE ) {
        pub_cancelMessage( &ctx );
        // Add error handling code.
        return errorCode;
    }
    
    // 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;
    }
    
    // Add the Bid Size field to the message.
    errorCode = pub_setInt32Field( &ctx, "Bid Size", Bid_Size );
    // errorCode = pub_setNullField( &ctx, "Bid Size" );
    if( errorCode != ERR_NONE ) {
        pub_cancelMessage( &ctx );
        // Add error handling code.
        return errorCode;
    }
    
    // Add the Yield field to the message.
    errorCode = pub_setDecimalField( &ctx, "Yield", Yield );
    // errorCode = pub_setDecimalFieldFromMantissa( &ctx, "Yield", Yield_Mantissa, Yield_Exponent );
    // errorCode = pub_setDecimalFieldFromString( &ctx, "Yield", Yield_String );
    // errorCode = pub_setNullField( &ctx, "Yield" );
    if( errorCode != ERR_NONE ) {
        pub_cancelMessage( &ctx );
        // Add error handling code.
        return errorCode;
    }
    
    // Send the completed message.
    errorCode = pub_sendMessage( &ctx );
    if( errorCode != ERR_NONE ) {
        pub_cancelMessage( &ctx );
        // Add error handling code.
    }
    return errorCode;
}
Related tasks
Generating a Publisher API Stub for a RAP Message
Developing a Publisher API Stub