Instantiating a Large SwitchKit Message

 

This section describes how to instantiate a SwitchKit message larger than the default size. The methods outlined in this section apply to all SwitchKit messages. When instantiating, the size of the message is defined as the size of the header plus data; not just the size of the message data. For example, if the header is eight bytes and data is 20 bytes, the total message size is 28 bytes.

The two methods for instantiating a message are:

Accept the default size

Customize the message size.

C SwitchKit programmers:

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

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

Or:

XL_SampleMessage sampleMessage;

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

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

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

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

C++ SwitchKit programmers:

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

XLC_SampleMessage *sampleMessagePtr =new XLC_SampleMessage;

Or

XLC_SampleMessage sampleMessage;

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

XLC_SampleMessage *sampleMessagePtr =new XLC_SampleMessage(1000);

Or

XLC_SampleMessage sampleMessage(1000);

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

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