DataLoader/MX Reference Manual (H06.03+, J06.03+)

Creating a Customized Version of DataLoader/MX
DataLoader/MX Reference Manual543544-001
5-18
Data Conversion
DTLSwitchEndian
This procedure converts big-endian fields to little-endian fields (or the reverse), in
place. Use this procedure when importing or exporting binary data from or to a system
whose byte order for binary fields is different from the byte order of the system running
DataLoader/MX.
The syntax is:
Buf is a pointer to the record whose fields are to be converted. NumFields is the
number of fields to be converted. Offsets is a pointer to NumFields 32-bit values
that give the offsets (counting from zero) of the fields to be converted. FieldSizes is
a pointer to NumFields 32-bit values that give the sizes of the fields whose offsets are
in the corresponding position of Offsets.
Example
This example uses the DTLSwitchEndian function in a CONVERTIT user exit to
reverse the bytes of binary integer fields when the data is being moved from a system
with one byte order to a system with another byte order.
Although it is extra work in set up, it is more efficient to use the compiler to compute
the offsets and lengths. Remember that filler bytes are dropped in when a field has to
be a multiple of 2, 4, or 8 bytes from the beginning of the structure. Therefore, it is not
accurate to count the bytes in a structure declaration.
sizes, offsets,arrays, and NumFields are declared static and are set up in the
initial data of the program so that they are not computed on every entry to
CONVERTIT.
#include "dtload.h" nolist
#include <assert.h> nolist
DTLEXP
void WINAPI CONVERTIT(
char* RecIn,
long* RecInLen,
char* RecOut,
long* RecOutLenMax,
long* RecOutLen,
short* Status
)
{
/* This is the record structure */
typedef struct
{
char c1[10];
long c2;
long c3;
char c4[20];
void DTLSwitchEndian (char* Buf, long* NumFields,
DTLLEN* Offsets, DTLLEN* FieldSizes);