JSON C Decode Functions

JSON C decode functions handle the decoding of simple XSD types. Calls to these functions are assembled in the C source code generated by the XBinder compiler to decode complex XML schema-based messages. In general, these complement the encoding model in which individual functions exist for each type.

As an example, the code documented above to encode a simple boolean value can be reversed to decode the value:

   OSBOOL      pdu;
   OSCTXT       ctxt;
   int          i, stat;
   const char*  filename = "message.json";

   /* Init context */

   stat = rtxInitContext (&ctxt);
   if (0 != stat) {
      printf ("Context initialization failed.\n");
      rtxErrPrint (&ctxt);
      return stat;
   }

   /* Create input source object */

   stat = rtxStreamFileCreateReader (&ctxt, filename);
   if (0 != stat) {
      printf ("Create file input stream failed.\n");
      rtxErrPrint (&ctxt);
      rtxFreeContext (&ctxt);
      return stat;
   }

   /* Call compiler generated decode function */
   if (stat == 0)
      stat = rtJsonDecBool (&ctxt, &pdu);

   if (stat == 0) {
      printf ("Decode was successful\n");
      printf ("Decoded record:\n");
      Print_Boolean ("Boolean", pdu);
   }
   else {
      printf ("decode failed\n");
      rtxErrPrint (&ctxt);
   }

   rtxStreamClose (&ctxt);
   rtxFreeContext (&ctxt);

A complete reference to all of the built-in C JSON decode functions is available in the XBinder C/C++ Runtime Reference Manual.