EMA C++ Developers Guide : 5 Provider Classes : 5.1 OmmProvider Class : 5.1.11 Packing with Providers : 5.1.11.2 Non-interactive Provider Packing Example
 
5.1.11.2 Non-interactive Provider Packing Example
The following example illustrates a Non-interactive Provider application setting up a basic PackedMsg object and packing messages together before submitting the PackedMsg.
 
 
void sendPackedMessagesExample(OmmProvider provider, UInt64 itemHandle)
{
    FieldList fieldList; // Field list used for message payload
 
    PackedMsg packedMsg(provider);
    packedMsg.initBuffer(); // Initialize buffer with default size of 6000. See reference manual for
        other uses of initBuffer().
 
    for (int i = 0; i < 10; i++) // Send 10 packed messages every second
    {
        for (int j = 0; j < 10; j++) // Pack 10 messages
        {
            fieldList.clear();
            fieldList.addReal(22, 3991 + j, OmmReal::ExponentNeg2Enum);
            fieldList.addReal(30, 10 + j, OmmReal::Exponent0Enum);
            fieldList.complete();
 
            UpdateMsg msg;
 
            msg.payload(fieldList);
            try
            {
                packedMsg.addMsg(msg, itemHandle); // Add message with its item handle
            }
            catch (const OmmInvalidUsageException& excp)
            {
                //The API was unable to add the current message into the packed buffer.
                //If messages have been successfully added to the packed buffer, submit them, get a new
                //packed buffer, and add the current message into that new buffer.
                if (excp.getErrorCode() == OmmInvalidUsageException::BufferTooSmallEnum)
                {
                    if (packedMsg.packedMsgCount() > 0) // Packed message has some data.
                    {
                        // Submit the messages we've already packed, get a new packed buffer, and add
                            the current message.
                        provider.submit(packedMsg); //Submit packed message on OmmProvider.
                        packedMsg.initBuffer(); // Re-initialize buffer for next set of packed
                            messages.
                        packedMsg.addMsg(msg, itemHandle); // Add missed message with its item handle
                    }
                    else
                    {
                        //Packed buffer too small to add even first message.
                        //Consider initializing the buffer to a higher value than the default 6000 bytes
                            if needed.
                        //See initBuffer() methods for more details.
                    }
                }
                else
                {
                    // Handle other exceptions from addMsg() here.
                }
            }
        }
 
        if (packedMsg.packedMsgCount() > 0)
        {
            provider.submit(packedMsg); // Submit packed message on OmmProvider.
            packedMsg.initBuffer(); // Re-initialize buffer for next set of packed messages.
        }
        else
        {
            // Nothing to submit because packed message is empty.
        }
        sleep(1000);
    }
}