Skip to content

WriteBasicTrePlugin15C

anna-dodd edited this page Jun 3, 2015 · 1 revision

Writing a basic TRE


TRE parsing, in the NITRO library, is done using plug-ins. This allows us the same extensibility provided to the NITF specification itself. When we have a plug-in that can read a TRE, we use it. When we can't we use a special default handler.

Our library was designed to support all types of TREs, but to make it especially easy to handle typical, straight-forward TREs. In most cases, plug-in writers don't have to write any actually "code" -- they can get away with simply declaring a parsing description as an array of TREDescription objects, followed by a special macro that declares that this code is a plug-in (the macro does a whole lot of work for us). First, we need to have a plug-in in a separate C file:

/*
 *  MYTREA.c - demonstrate creation of a TRE handler for a made up TRE.
 */

#include <import/nitf.h>

static nitf_TREDescription description[] = {
    { NITF_BCS_A, 32, "Creator Name", "CREATOR", NITF_VAL_BCS_A_PLUS, NITF_NO_RANGE, NULL, NULL },
    { NITF_BCS_N, 4, "Num Contributors", "NCONTRIB", NITF_VAL_BCS_N_PLUS, NITF_NO_RANGE, NULL, NULL},
    { NITF_LOOP, 0, NULL, "NCONTRIB" }, /* Want to loop NCONTRIB times */
        { NITF_BCS_A, 32, "Contributor Name", "CONTRIBUTOR", NITF_VAL_BCS_A_PLUS, NITF_NO_RANGE, NULL, NULL},
    { NITF_ENDLOOP, 0, NULL, NULL},
    {NITF_END, 0, NULL, NULL}
}

/*
 * When we want to retrieve this data from our application, we need to get the TREs field named
 * CONTRIBUTOR[0], CONTRIBUTOR[1], ..., CONTRIBUTOR[ncontrib-1]
 */


/* Expose this plugin */
NITF_DECLARE_SINGLE_PLUGIN(MYTREA, description)


For more examples, check out the shared section of our library. There are many examples that illustrate the syntax allowed in the TREDescription structures.
Clone this wiki locally