bvstone

YAJL Update

Posted:

YAJL Update

A while back I was trying to find out if the YAJL port from Scott Klement had a function that would return a pointer to node data as well as get the length.  See this thread:

http://archive.midrange.com/rpg400-l/201604/msg00138.html

What Scott, Barbara (and a little bit of me) came up with were to create two new subprocedures.  Following additions to the member YAJLR4 in QRPGLESRC:

      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * YAJL_GET_STRING_UTF8(): Retrieve a pointer to the raw UTF-8
      *                         data for a YAJL string
      *
      *   node = (input) YAJL tree node
      *
      * returns a pointer to a C-style, zero-terminated string
      *      or *NULL if the node is not a string
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P YAJL_GET_STRING_UTF8...
     P                 B                   export
     D                 PI              *
     D   node                              like(yajl_val) value

     D nv              ds                  likeds(yajl_val_t)
     D                                     based(node)

      /free
       if YAJL_IS_STRING(node);
         return nv.string;
       else;
         return *null;
       endif;
      /end-free
     P                 E

      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * YAJL_GET_STRING_BUF(): Retrieve a pointer to the YAJL String
      *
      *   node = (input) YAJL tree node
      *   buf = (input) pointer to buffer to load
      *   bufSize = (input) size of buffer to load
      *
      * returns size of buffer or -1 for error
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P YAJL_GET_STRING_BUF...
     P                 B                   export
     D                 PI            10U 0
     D   node                              like(yajl_val) value
     D   buf                           *   value
     D   bufSize                     10U 0 value

     D memcpy          pr              *   extproc('memcpy')
     D   dst                           *   value
     D   src                           *   value
     D   len                         10u 0 value

     d strlen          PR            10u 0 extproc('strlen')
     d  p                              *   value

     D nv              ds                  likeds(yajl_val_t)
     D                                     based(node)
     D str             s               *
     D len             s             10u 0
      /free
       if YAJL_IS_STRING(node);
          init_gconv();
          str = yajl_iconv_toLocal( gConv: nv.string );
          len = strlen(str);

          if (len > bufSize);
            len = bufSize;
          endif;

          memcpy(buf:str:len);
          yajl_iconv_string_free(str);
          return len;
       else;
          return -1;
       endif;
      /end-free
     P                 E

The YAJL_GET_STRING_UTF8 is exactly how Scott suggested.

The YAJL_GET_STRING_BUF is a little different.  Instead of returning a boolean (indicator) it returns the size of the string (or -1 for an error).

Here's an example of how I am using it:

 val = YAJL_object_find(node:'data');
 
 data@ = %alloc(MAX_SIZE);

 if (data@ = *null);
   //error
 endif;

 rc = yajl_get_string_buf(val:data@:MAX_SIZE);

 // do stuff with the data

 dealloc(en) l_data@;

After the call to yajl_get_string_buf, the variable rc will contain the size of the data and data@ will point to the data, converted from UTF8 to the jobs CCSID.

Other changes made were to the following additions to the /copy member YAJL_H in QRPGLESRC:

      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * YAJL_GET_STRING_UTF8(): Retrieve a pointer to the raw UTF-8
      *                         data for a YAJL string
      *
      *   node = (input) YAJL tree node
      *
      * returns a pointer to a C-style, zero-terminated string
      *      or *NULL if the node is not a string
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D YAJL_GET_STRING_UTF8...
     D                 PR              *
     D   node                              like(yajl_val) value

      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * YAJL_GET_STRING_BUF(): Retrieve a pointer to the YAJL String
      *
      *   node = (input) YAJL tree node
      *   buf = (input) pointer to buffer to load
      *   bufSize = (input) size of buffer to load
      *
      * returns size of buffer or -1 for error
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     D YAJL_GET_STRING_BUF...
     D                 PR            10u 0
     D   node                              like(yajl_val) value
     D   buf                           *   value
     D   bufSize                     10u 0 value

And finally the updated binder langauge member YAJLR4 in QSRVSRC:

STRPGMEXP  SIGNATURE('YAJLR4 1.1      ')
  export symbol(yajl_buf_parse)
  export symbol(yajl_stmf_parse)
  export symbol(yajl_buf_load_tree)
  export symbol(yajl_stmf_load_tree)
  export symbol(yajl_is_array)
  export symbol(yajl_is_false)
  export symbol(yajl_is_null)
  export symbol(yajl_is_number)
  export symbol(yajl_is_object)
  export symbol(yajl_is_string)
  export symbol(yajl_is_true)
  export symbol(yajl_get_number)
  export symbol(yajl_get_string)
  export symbol(yajl_array_elem)
  export symbol(yajl_array_loop)
  export symbol(yajl_array_size)
  export symbol(yajl_object_elem)
  export symbol(yajl_object_find)
  export symbol(yajl_object_loop)
  export symbol(yajl_object_size)
  export symbol(yajl_genOpen)
  export symbol(yajl_genClose)
  export symbol(yajl_beginObj)
  export symbol(yajl_endObj)
  export symbol(yajl_beginArray)
  export symbol(yajl_endArray)
  export symbol(yajl_addChar)
  export symbol(yajl_addNum)
  export symbol(yajl_addBool)
  export symbol(yajl_addNull)
  export symbol(yajl_copyBuf)
  export symbol(yajl_saveBuf)
  export symbol(yajl_writeStdout)
  export symbol(yajl_stdin_load_tree)
  export symbol(yajl_addCharEx)
  export symbol(yajl_addCharStmf)
  export symbol(yajl_exbuf_new)
  export symbol(yajl_exbuf_concat_ptr)
  export symbol(yajl_exbuf_concat)
  export symbol(yajl_exbuf_free)
  export symbol(yajl_save_string_stmf)
  export symbol(yajl_getBuf)
  export symbol(yajl_tree_free_rpg)
  export symbol(yajl_get_string_utf8)
  export symbol(yajl_get_string_buf)
endpgmexp
STRPGMEXP  PGMLVL(*PRV) SIGNATURE('YAJLR4 1.0      ')
  export symbol(yajl_buf_parse)
  export symbol(yajl_stmf_parse)
  export symbol(yajl_buf_load_tree)
  export symbol(yajl_stmf_load_tree)
  export symbol(yajl_is_array)
  export symbol(yajl_is_false)
  export symbol(yajl_is_null)
  export symbol(yajl_is_number)
  export symbol(yajl_is_object)
  export symbol(yajl_is_string)
  export symbol(yajl_is_true)
  export symbol(yajl_get_number)
  export symbol(yajl_get_string)
  export symbol(yajl_array_elem)
  export symbol(yajl_array_loop)
  export symbol(yajl_array_size)
  export symbol(yajl_object_elem)
  export symbol(yajl_object_find)
  export symbol(yajl_object_loop)
  export symbol(yajl_object_size)
  export symbol(yajl_genOpen)
  export symbol(yajl_genClose)
  export symbol(yajl_beginObj)
  export symbol(yajl_endObj)
  export symbol(yajl_beginArray)
  export symbol(yajl_endArray)
  export symbol(yajl_addChar)
  export symbol(yajl_addNum)
  export symbol(yajl_addBool)
  export symbol(yajl_addNull)
  export symbol(yajl_copyBuf)
  export symbol(yajl_saveBuf)
  export symbol(yajl_writeStdout)
  export symbol(yajl_stdin_load_tree)
  export symbol(yajl_addCharEx)
  export symbol(yajl_addCharStmf)
  export symbol(yajl_exbuf_new)
  export symbol(yajl_exbuf_concat_ptr)
  export symbol(yajl_exbuf_concat)
  export symbol(yajl_exbuf_free)
  export symbol(yajl_save_string_stmf)
  export symbol(yajl_getBuf)
  export symbol(yajl_tree_free_rpg)
endpgmexp

 


Last edited 05/27/2016 at 16:04:14



Latest Posts:

YAJL - Parsing YAJL - Parsing
Posted by April 4, 2021
Programming >> RPG Programming
Create LPAR partition and install OS Create LPAR partition and install OS
Posted by March 24, 2021
IBM Power Systems >> (QGPL) IBM i
G4MS Now Allows User/Password Authentication Option G4MS Now Allows User/Password Authentication Option
Posted by March 16, 2021
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
IPDS printer file using CHRSIZ IPDS printer file using CHRSIZ
Posted by February 25, 2021
Programming >> RPG Programming
How to Correctly Send the Display Machine Information (DSPMCHINF) Data to BVSTools for Key Generation How to Correctly Send the Display Machine Information (DSPMCHINF) Data to BVSTools for Key Generation
Posted by February 9, 2021
BVSTools >> BVSTools Software Discussion
G4MS Updated to v7.10 - Required Update for All G4MS Users G4MS Updated to v7.10 - Required Update for All G4MS Users
Posted by November 12, 2020
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
MAILTOOL Errors with Microsoft Office 365 (2020) MAILTOOL Errors with Microsoft Office 365 (2020)
Posted by September 3, 2020
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
Using MAILTOOL With Office 365 and Two Factor Authentication (2FA or MFA) Using MAILTOOL With Office 365 and Two Factor Authentication (2FA or MFA)
Posted by August 17, 2020
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
Updating DNS With Dynamic IP Addresses After a Router Reboot/Power Outage Updating DNS With Dynamic IP Addresses After a Router Reboot/Power Outage
Posted by August 16, 2020
Programming >> Proof of Concept (POC)
GETURI v10.10 Released with New ILE Functions GETURI v10.10 Released with New ILE Functions
Posted by August 12, 2020
BVSTools >> BVSTools Announcements >> Get URI (GETURI) Specific Announcements
MAILTOOL Updated to Allow G4GSMAIL as Option in Routers File MAILTOOL Updated to Allow G4GSMAIL as Option in Routers File
Posted by June 28, 2020
BVSTools >> BVSTools Announcements >> eMail Tool (MAILTOOL) Specific Announcements
BVSTools Now Offers Interface with Infor's ION APIs BVSTools Now Offers Interface with Infor's ION APIs
Posted by May 15, 2020
BVSTools >> BVSTools Announcements
More V7R4 IFS File CCSID Issues and The Fix More V7R4 IFS File CCSID Issues and The Fix
Posted by March 4, 2020
IBM Power Systems >> (QGPL) IBM i
Error Retrieving IP Address by Name Error Retrieving IP Address by Name
Posted by February 25, 2020
BVSTools >> BVSTools Software Discussion
Logging jobs that hit an outq Logging jobs that hit an outq
Posted by February 13, 2020
Programming >> CL Programming

Reply




Copyright 1983-2020 BVSTools
GreenBoard(v3) Powered by the eRPG SDK, MAILTOOL Plus!, GreenTools for Google Apps, jQuery, jQuery UI, BlockUI, CKEditor and running on the IBM i (AKA AS/400, iSeries, System i).