You are here: SwitchKit® Development Environment Programmer’s Guide > 7 Message Functions > Instantiating a SwitchKit Message

Instantiating a SwitchKit Message

This section describes how to instantiate a SwitchKit message. The SwitchKit API is modified as necessary to accommodate new features and functionality. When this modification occurs, additional data may be added to an existing message. Each SwitchKit message has a default size for convenience. To future proof applications, Dialogic recommends the default size be overridden with a larger buffer.

The methods outlined in this section apply to all SwitchKit messages.

Note: The amount of memory allocated when instantiating a message should be much larger than the actual EXS API message definition. When sending the message, SwitchKit will send only the number of bytes defined by the EXS API, not the number of bytes allocated. Allocating a larger buffer future proofs the application.

The following are the two methods for instantiating a message:

• Specify the message size which is the recommended method

• Accept the default size.

C SwitchKit programmers:

To instantiate a custom-sized message, do one of the following:

#define MAX_MESSAGE_SIZE 1000

XL_SampleMessage *sampleMessagePtr = (XL_SampleMessage *)malloc(MAX_MESSAGE_SIZE);

Then copy the data into the message (where dataSize is the actual size of the data for the message):

dataSize= SizeOfDataBuf;

memcpy (sampleMessagePtr->Data, buf, dataSize);

To accept the default size of a message, do one of the following:

XL_SampleMessage *sampleMessagePtr = (XL_SampleMessage *)malloc(sizeof XL_SampleMessage);

C++ SwitchKit programmers:

To instantiate a custom-sized message, do the following:

#define MAX_MESSAGE_SIZE 1000

XLC_SampleMessage *sampleMessagePtr =new XLC_SampleMessage(MAX_MESSAGE_SIZE);

Or

XLC_SampleMessage sampleMessage(msgSize);

Then copy the data into the message (where dataSize is the actual size of the data for the message)

dataSize= SizeOfDataBuf;

memcpy (sampleMessagePtr->getDataPtr(), buf, dataSize);

To accept the default size of a message, do one of the following:

XLC_SampleMessage *sampleMessagePtr =new XLC_SampleMessage;

Or

XLC_SampleMessage sampleMessage;

Note: It is strongly recommended that setData() NOT be used to copy data into a SwitchKit API message as setData() copies a constant number of bytes regardless of number of bytes allocated or used.

Note: A subset of SwitchKit API messages use ICBData in place of Data in their C structure and C++ class definitions. The example code above for instantiating and populating messages applies to these as well.