tpf_dfdl_createData: Create a data stream for a DFDL schema

This function creates a data stream that is defined by a Data Format Description Language (DFDL) schema.

Last updated

  • Changed in 2023.
  • Changed in 2022 (information only; no code change).
  • Added in 2021.

Format

LIBS := DFDL

#include <tpf/cdfdl.h>

void *tpf_dfdl_createData(DFDLHandle dfdlhdl,
                          unsigned int *data_length,
                          int options);
dfdlhdl
A DFDL API handle that is associated with the DFDL structure.
data_length
A pointer to the location to store the size of the data stream that is serialized. Specify NULL for this parameter if the size of the data stream is not needed.
options
Specifies the processing options for this function. Specify any of the following values:
0
No special processing is requested. The fields that are not required are created with the default value while required fields result in an error.
TPF_DFDL_PTR2OFF
In the data stream, locations that are defined in the DFDL schema as containing an indirection of the pointer type are converted to an offset from the start of the created data stream. If the DFDL API handle is associated with a data stream, the corresponding field values in the associated data stream are used for all field values in the created data stream.
TPF_DFDL_VERIFY
Verify whether the data conforms to the DFDL schema restrictions. Data that does not conform to the DFDL schema restrictions causes a std::runtime_error exception to be thrown.

Normal return

A pointer to the data stream that contains the created data.

Error return

None.

Exceptions

If an error occurs, one of the following exceptions is issued:
  • std::bad_alloc
  • std::invalid_argument
  • std::length_error
  • std::logic_error
  • std::runtime_error

Programming considerations

  • You must initialize the DFDL handle by calling the tpf_dfdl_initialize_handle function.
  • You must call the free function to release the storage that was allocated for the created data. The storage location to be released is identified by the address that this function returns.

Example

The following example shows how to create a data stream with default values.
#include <tpf/cdfdl.h>
#include <stdexcept>
.
.
.
DFDLHandle dh;
struct mydata *buf;

#define DFDL_FILE "mydata.gen.dfdl.xsd"
#define DFDL_ROOT "mydata"
.
.
.
try {
   tpf_dfdl_initialize_handle(&dh, DFDL_FILE, DFDL_ROOT, 0);

   buf = (struct mydata *) tpf_dfdl_createData(dh, NULL, 0);
}
catch (std::exception &e) {
   // error
}
tpf_dfdl_terminate_handle(dh);