MSJSON - JSON serialize (parse) native micro library

Тема в разделе "WASM.SOURCES & 2LZ", создана пользователем HESH, 17 янв 2023.

  1. HESH

    HESH Active Member

    Публикаций:
    2
    Регистрация:
    20 мар 2008
    Сообщения:
    143
    ;============================== [ MSJSON Library ReadMe ] ==============================
    ;
    ; What is it:
    ;
    ; MSJSON - is universal native micro (<10 kb) library for serializing (parsing) JSON objects, based on Microsoft's
    ; JavaScript Engine (jscript.dll). Release has been divided on 2 category: Static and Dynamic builds. In case with
    ; Static build, all MSJSON library binary code will be combined with main executable file. In case with Dynamic build
    ; all binary code will be stored in .dll file which can be loaded automatically at any time.
    ;
    ; Static build contain:
    ;
    ; 1. MSJSON.inc - header file for MASM32 project with some basics declarations.
    ; 2. MSJSON.lib - library file for connecting to project.
    ;
    ; Dynamic build contain:
    ;
    ; 1. MSJSON.inc - header file for MASM32 project with some basics declarations.
    ; 2. MSJSON.lib - library file for connecting to project.
    ; 3. MSJSON.dll - .dll file for keeping in folder with main executable file if you will select dynamic build.
    ;
    ; All this files has been developed for MASM32, but you can use this library in your own project on any other lang.
    ; You need only redefine MSJSON.inc file use your's lang syntax and connect to project static or dynamic MSJSON.lib.
    ;
    ; In addition, as bonus, MSJSON release contain JSONView project with open source code, demonstrate how to use
    ; this library. Source code has own comments. JSONView program recursively build tree of JSON objects and display
    ; them items types/values.
    ;
    ; P.S.: Quality of parsing is guaranted by MS :lol:
    ;
    ; © HESH FROMSTARS
    ; 17.01.2023

    ; File MSJSON.inc (static and dynamic) contain definitions of 9 constants, 1 union and 16 functions. Their description
    ; is given below.
    ;
    ; JOIVT_* Constants is JSON Objects Items Values Types (JOIVT):
    ;
    ; JOIVT_UNKNOWN equ 0 ; Unknown item value type.
    ; JOIVT_STRING equ 1 ; Item value is sz-string.
    ; JOIVT_OBJECT equ 2 ; Item value is handle to object item.
    ; JOIVT_I4 equ 3 ; Item value is 32-bit integer.
    ; JOIVT_UI4 equ 4 ; Item value is 32-bit unsigned integer.
    ; JOIVT_I8 equ 5 ; Item value is 64-bit integer.
    ; JOIVT_UI8 equ 6 ; Item value is 64-bit unsigned integer.
    ; JOIVT_R4 equ 7 ; Item value is 32-bit real.
    ; JOIVT_R8 equ 8 ; Item value is 64-bit real.
    ;
    ; JSONItemValue union contain possible items values. Maximum value length (for variables with JSONItemValue type) is qword (8 bytes).
    ;
    ; hStringVal dword ? ; for JOIVT_STRING values.
    ; hObjectItem dword ? ; for JOIVT_OBJECT values.
    ; dwInt32 dword ? ; for JOIVT_I4 and JOIVT_UI4 values.
    ; qwInt64 qword ? ; for JOIVT_I8 and JOIVT_UI8 values.
    ; dwFloat32 dword ? ; for JOIVT_R4 values.
    ; qwFloat64 qword ? ; for JOIVT_R8 values.
    ;
    ;
    ; Functions:
    ;
    ;
    ; 1.
    ; ;=============== MSJSONInit Function ===============
    ; ;
    ; ; Description:
    ; ;
    ; ; Initialize MSJSON library.
    ; ;
    ; ; Arguments:
    ; ;
    ; ; -
    ; ;
    ; ; Return value:
    ; ;
    ; ; 1 if success, 0 otherwise.
    ; ;
    ; ; Note:
    ; ;
    ; ; MSJSONInit proto stdcall
    ; ;
    ;
    ;
    ; 2.
    ; ;=============== ParseA Function ===============
    ; ;
    ; ; Description:
    ; ;
    ; ; Parse ASCII JSON text.
    ; ;
    ; ; Arguments:
    ; ;
    ; ; [in] pszJSONTextA - pointer to ASCII string.
    ; ;
    ; ; Return value:
    ; ;
    ; ; 1 if success, 0 otherwise.
    ; ;
    ; ; Note:
    ; ;
    ; ; ParseA proto stdcall pszJSONTextA:dword
    ; ;
    ;
    ;
    ; 3.
    ; ;=============== ParseW Function ===============
    ; ;
    ; ; Description:
    ; ;
    ; ; Parse Unicode JSON text.
    ; ;
    ; ; Arguments:
    ; ;
    ; ; [in] pszJSONTextW - pointer to Unicode string.
    ; ;
    ; ; Return value:
    ; ;
    ; ; 1 if success, 0 otherwise.
    ; ;
    ; ; Note:
    ; ;
    ; ; ParseW proto stdcall pszJSONTextW:dword
    ; ;
    ;
    ;
    ; 4.
    ; ;=============== GetItemsCount Function ===============
    ; ;
    ; ; Description:
    ; ;
    ; ; Get count of items in JSON Objects.
    ; ;
    ; ; Arguments:
    ; ;
    ; ; [in] hObjectItem - handle of JSON object item.
    ; ;
    ; ; Return value:
    ; ;
    ; ; Count of items if success, 0 otherwise.
    ; ;
    ; ; Note:
    ; ;
    ; ; GetItemsCount proto stdcall hObjectItem:dword
    ; ;
    ;
    ;
    ; 5.
    ; ;=============== FindFirstItemA Function ===============
    ; ;
    ; ; Description:
    ; ;
    ; ; Find first item in JSON object.
    ; ;
    ; ; Arguments:
    ; ;
    ; ; [in] hObjectItem - handle of JSON object item.
    ; ; [in, out, optional] pszItemName - pointer to a variable which contain pointer to ASCII string on return.
    ; ; [in, out, optional] pItemVal - pointer to a variable of JSONItemValue type which contain item value on return.
    ; ;
    ; ; Return value:
    ; ;
    ; ; If success, in eax will be return one of JOIVT_* constants for current ItemVal, JOIVT_UNKNOWN otherwise.
    ; ;
    ; ; Note:
    ; ;
    ; ; FindFirstItemA proto stdcall hObjectItem:dword, pszItemName:dword, pItemVal:dword
    ; ;
    ;
    ;
    ; 6.
    ; ;=============== FindFirstItemW Function ===============
    ; ;
    ; ; Description:
    ; ;
    ; ; Find first item in JSON object. Unicode version of FindFirstItemA.
    ; ;
    ; ; Arguments:
    ; ;
    ; ; [in] hObjectItem - handle of JSON object item.
    ; ; [in, out, optional] pszItemName - pointer to a variable which contain pointer to Unicode string on return.
    ; ; [in, out, optional] pItemVal - pointer to a variable of JSONItemValue type which contain item value on return.
    ; ;
    ; ; Return value:
    ; ;
    ; ; If success, in eax will be return one of JOIVT_* constants for current ItemVal, JOIVT_UNKNOWN otherwise.
    ; ;
    ; ; Note:
    ; ;
    ; ; FindFirstItemW proto stdcall hObjectItem:dword, pszItemName:dword, pItemVal:dword
    ; ;
    ;
    ;
    ; 7.
    ; ;=============== FindNextItemA Function ===============
    ; ;
    ; ; Description:
    ; ;
    ; ; Find next item in JSON object.
    ; ;
    ; ; Arguments:
    ; ;
    ; ; [in] hObjectItem - handle of JSON object item.
    ; ; [in, out, optional] pszItemName - pointer to a variable which contain pointer to ASCII string on return.
    ; ; [in, out, optional] pItemVal - pointer to a variable of JSONItemValue type which contain item value on return.
    ; ;
    ; ; Return value:
    ; ;
    ; ; If success, in eax will be return one of JOIVT_* constants for current ItemVal, JOIVT_UNKNOWN otherwise.
    ; ;
    ; ; Note:
    ; ;
    ; ; FindNextItemA proto stdcall hObjectItem:dword, pszItemName:dword, pItemVal:dword
    ; ;
    ;
    ;
    ; 8.
    ; ;=============== FindNextItemW Function ===============
    ; ;
    ; ; Description:
    ; ;
    ; ; Find next item in JSON object. Unicode version of FindNextItemA.
    ; ;
    ; ; Arguments:
    ; ;
    ; ; [in] hObjectItem - handle of JSON object item.
    ; ; [in, out, optional] pszItemName - pointer to a variable which contain pointer to Unicode string on return.
    ; ; [in, out, optional] pItemVal - pointer to a variable of JSONItemValue type which contain item value on return.
    ; ;
    ; ; Return value:
    ; ;
    ; ; If success, in eax will be return one of JOIVT_* constants for current ItemVal, JOIVT_UNKNOWN otherwise.
    ; ;
    ; ; Note:
    ; ;
    ; ; FindNextItemW proto stdcall hObjectItem:dword, pszItemName:dword, pItemVal:dword
    ; ;
    ;
    ;
    ; 9.
    ; ;=============== GetItemByIndexA Function ===============
    ; ;
    ; ; Description:
    ; ;
    ; ; Get info about item with custom index.
    ; ;
    ; ; Arguments:
    ; ;
    ; ; [in] hObjectItem - handle of JSON object item.
    ; ; [in] dwItemIndex - integer item 0-based index in JSON object.
    ; ; [in, out, optional] pszItemName - pointer to a variable which contain pointer to ASCII string on return.
    ; ; [in, out, optional] pItemVal - pointer to a variable of JSONItemValue type which contain item value on return.
    ; ;
    ; ; Return value:
    ; ;
    ; ; If success, in eax will be return one of JOIVT_* constants for current ItemVal, JOIVT_UNKNOWN otherwise.
    ; ;
    ; ; Note:
    ; ;
    ; ; GetItemByIndexA proto stdcall hObjectItem:dword, dwItemIndex:dword, pszItemName:dword, pItemVal:dword
    ; ;
    ;
    ;
    ; 10.
    ; ;=============== GetItemByIndexW Function ===============
    ; ;
    ; ; Description:
    ; ;
    ; ; Get info about item with custom index. Unicode version of GetItemByIndexA.
    ; ;
    ; ; Arguments:
    ; ;
    ; ; [in] hObjectItem - handle of JSON object item.
    ; ; [in] dwItemIndex - integer item 0-based index in JSON object.
    ; ; [in, out, optional] pszItemName - pointer to a variable which contain pointer to ASCII string on return.
    ; ; [in, out, optional] pItemVal - pointer to a variable of JSONItemValue type which contain item value on return.
    ; ;
    ; ; Return value:
    ; ;
    ; ; If success, in eax will be return one of JOIVT_* constants for current ItemVal, JOIVT_UNKNOWN otherwise.
    ; ;
    ; ; Note:
    ; ;
    ; ; GetItemByIndexW proto stdcall hObjectItem:dword, dwItemIndex:dword, pszItemName:dword, pItemVal:dword
    ; ;
    ;
    ;
    ; 11.
    ; ;=============== GetItemByNameA Function ===============
    ; ;
    ; ; Description:
    ; ;
    ; ; Get named item value.
    ; ;
    ; ; Arguments:
    ; ;
    ; ; [in] hObjectItem - handle of JSON object item.
    ; ; [in] pszItemName - pointer to ASCII-name of item.
    ; ; [in, out, optional] pItemVal - pointer to a variable of JSONItemValue type which contain item value on return.
    ; ;
    ; ; Return value:
    ; ;
    ; ; If success, in eax will be return one of JOIVT_* constants for current ItemVal, JOIVT_UNKNOWN otherwise.
    ; ;
    ; ; Note:
    ; ;
    ; ; GetItemByNameA proto stdcall hObjectItem:dword, pszItemName:dword, pItemVal:dword
    ; ;
    ;
    ;
    ; 12.
    ; ;=============== GetItemByNameW Function ===============
    ; ;
    ; ; Description:
    ; ;
    ; ; Get named item value. Unicode version of GetItemByNameA.
    ; ;
    ; ; Arguments:
    ; ;
    ; ; [in] hObjectItem - handle of JSON object item.
    ; ; [in] pszItemName - pointer to ASCII-name of item.
    ; ; [in, out, optional] pItemVal - pointer to a variable of JSONItemValue type which contain item value on return.
    ; ;
    ; ; Return value:
    ; ;
    ; ; If success, in eax will be return one of JOIVT_* constants for current ItemVal, JOIVT_UNKNOWN otherwise.
    ; ;
    ; ; Note:
    ; ;
    ; ; GetItemByNameW proto stdcall hObjectItem:dword, pszItemName:dword, pItemVal:dword
    ; ;
    ;
    ;
    ; 13.
    ; ;=============== ItemNameFree Function ===============
    ; ;
    ; ; Description:
    ; ;
    ; ; Free item name.
    ; ;
    ; ; Arguments:
    ; ;
    ; ; [in] hItemName - pointer to allocated by other functions name of item.
    ; ;
    ; ; Return value:
    ; ;
    ; ; 1 if success, 0 otherwise.
    ; ;
    ; ; Note:
    ; ;
    ; ; ItemNameFree proto stdcall hItemName:dword
    ; ;
    ;
    ;
    ; 14.
    ; ;=============== ItemValFree Function ===============
    ; ;
    ; ; Description:
    ; ;
    ; ; Free item value.
    ; ;
    ; ; Arguments:
    ; ;
    ; ; [in] hItemVal - pointer to allocated by other functions string value of item. Applies only for JOIVT_STRING.
    ; ;
    ; ; Return value:
    ; ;
    ; ; 1 if success, 0 otherwise.
    ; ;
    ; ; Note:
    ; ;
    ; ; ItemValFree proto stdcall hItemVal:dword
    ; ;
    ;
    ;
    ; 15.
    ; ;=============== ItemRelease Function ===============
    ; ;
    ; ; Description:
    ; ;
    ; ; Destroy item handle and free associated resources.
    ; ;
    ; ; Arguments:
    ; ;
    ; ; [in] hItem - handle to JSON item, returned by other functions.
    ; ;
    ; ; Return value:
    ; ;
    ; ; 1 if success, 0 otherwise.
    ; ;
    ; ; Note:
    ; ;
    ; ; ItemRelease proto stdcall hItem:dword
    ; ;
    ;
    ;
    ; 16.
    ; ;=============== ItemRelease Function ===============
    ; ;
    ; ; Description:
    ; ;
    ; ; Uninitialize MSJSON library.
    ; ;
    ; ; Arguments:
    ; ;
    ; ; -
    ; ;
    ; ; Return value:
    ; ;
    ; ; 1 if success, 0 otherwise.
    ; ;
    ; ; Note:
    ; ;
    ; ; MSJSONRelease proto stdcall
    ; ;
     

    Вложения:

    Application и Rel нравится это.
  2. Mikl___

    Mikl___ Супермодератор Команда форума

    Публикаций:
    14
    Регистрация:
    25 июн 2008
    Сообщения:
    3.709
    HESH,
    вы бы еще пару строк на русском добавили ;)
     
  3. HESH

    HESH Active Member

    Публикаций:
    2
    Регистрация:
    20 мар 2008
    Сообщения:
    143
    Отвечу на любой вопрос по теме :)
     
  4. Mikl___

    Mikl___ Супермодератор Команда форума

    Публикаций:
    14
    Регистрация:
    25 июн 2008
    Сообщения:
    3.709
    HESH,
    я на masm32.com не нашел проекта MSJSON, возможно, что плохо искал?
     
  5. HESH

    HESH Active Member

    Публикаций:
    2
    Регистрация:
    20 мар 2008
    Сообщения:
    143