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:

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
GreenTools for Google Apps (G4G) v12.60 Released with Shared Drive Features and More... GreenTools for Google Apps (G4G) v12.60 Released with Shared Drive Features and More...
Posted by February 4, 2020
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
Allowing Requests over Port 80 For SSL Validation (ie, Namecheap, etc) Allowing Requests over Port 80 For SSL Validation (ie, Namecheap, etc)
Posted by January 31, 2020
Programming >> Web Programming
GreenTools for Slack (G4SLK) v3.00 Released GreenTools for Slack (G4SLK) v3.00 Released
Posted by January 17, 2020
BVSTools >> BVSTools Announcements >> GreenTools for Slack (G4SLK) Specific Announcements
Calling a QSH Command from RPG Calling a QSH Command from RPG
Posted by December 26, 2019
Programming >> RPG Programming
SPLTOOL Print Range (PRTRNG) Function Updated to Handle Spooled Files up to 999,999,999 Pages SPLTOOL Print Range (PRTRNG) Function Updated to Handle Spooled Files up to 999,999,999 Pages
Posted by December 14, 2019
BVSTools >> BVSTools Announcements >> Spooled File Tools (SPLTOOL) Specific Announcements
GreenTools for Microsoft Apps (G4MS) Updated to v6.00 - Now Uses Microsoft Graph APIs GreenTools for Microsoft Apps (G4MS) Updated to v6.00 - Now Uses Microsoft Graph APIs
Posted by November 24, 2019
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
V7R4 Changes CCSID of Compressed File Using PASE JAR Command - Here's The Fix V7R4 Changes CCSID of Compressed File Using PASE JAR Command - Here's The Fix
Posted by November 21, 2019
IBM Power Systems >> (QGPL) IBM i
Using GETURI to Make OAuth 2.0 Requests - Custom Headers for Access Tokens Using GETURI to Make OAuth 2.0 Requests - Custom Headers for Access Tokens
Posted by November 11, 2019
BVSTools >> BVSTools Software Discussion >> Get URI (GETURI) Specific Discussion
GreenTools for Microsoft Apps (G4MS) v5.00 Released with Updated OneDrive Support and 3rd Party Functionality GreenTools for Microsoft Apps (G4MS) v5.00 Released with Updated OneDrive Support and 3rd Party Functionality
Posted by October 20, 2019
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
BVSTools is Now Running V7R4M0 BVSTools is Now Running V7R4M0
Posted by September 28, 2019
BVSTools >> BVSTools Announcements
GreenTools for G Suite (G4G) Now Includes Send Mail Functionality (G4GSMAIL Addon) GreenTools for G Suite (G4G) Now Includes Send Mail Functionality (G4GSMAIL Addon)
Posted by August 27, 2019
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements

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).