VirtualBox

Changeset 83425 in vbox


Ignore:
Timestamp:
Mar 25, 2020 7:37:25 PM (5 years ago)
Author:
vboxsync
Message:

RUntime/RTJson: Add parse from VFS file method

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/json.h

    r82968 r83425  
    125125
    126126/**
     127 * Parses a JSON document from the given VFS file
     128 * returning the root JSON value.
     129 *
     130 * @returns IPRT status code.
     131 * @retval  VERR_JSON_MALFORMED if the document does not conform to the spec.
     132 * @param   phJsonVal       Where to store the handle to the JSON value on success.
     133 * @param   hVfsFile        The VFS file to parse.
     134 * @param   pErrInfo        Where to store extended error info. Optional.
     135 */
     136RTDECL(int) RTJsonParseFromVfsFile(PRTJSONVAL phJsonVal, RTVFSFILE hVfsFile, PRTERRINFO pErrInfo);
     137
     138/**
    127139 * Retain a given JSON value.
    128140 *
  • trunk/include/iprt/mangling.h

    r83369 r83425  
    11711171# define RTJsonParseFromFile                            RT_MANGLER(RTJsonParseFromFile)
    11721172# define RTJsonParseFromString                          RT_MANGLER(RTJsonParseFromString)
     1173# define RTJsonParseFromVfsFile                         RT_MANGLER(RTJsonParseFromVfsFile)
    11731174# define RTJsonValueGetArraySize                        RT_MANGLER(RTJsonValueGetArraySize)
    11741175# define RTJsonValueGetString                           RT_MANGLER(RTJsonValueGetString)
  • trunk/src/VBox/Runtime/common/misc/json.cpp

    r82968 r83425  
    4040#include <iprt/string.h>
    4141#include <iprt/utf16.h>
     42#include <iprt/vfs.h>
    4243
    4344#include <stdlib.h> /* strtod() */
     
    260261        PRTSTREAM           hStream;
    261262        const uint8_t       *pbBuf;
     263        RTVFSFILE           hVfsFile;
    262264    } u;
    263265} RTJSONREADERARGS;
     
    14291431}
    14301432
     1433/**
     1434 * Read callback for RTJsonParseFromVfsFile().
     1435 */
     1436static DECLCALLBACK(int) rtJsonTokenizerParseFromVfsFile(void *pvUser, size_t offInput,
     1437                                                         void *pvBuf, size_t cbBuf,
     1438                                                         size_t *pcbRead)
     1439{
     1440    PRTJSONREADERARGS pArgs = (PRTJSONREADERARGS)pvUser;
     1441
     1442    RT_NOREF_PV(offInput);
     1443
     1444    size_t cbRead = 0;
     1445    int rc = RTVfsFileRead(pArgs->u.hVfsFile, pvBuf, cbBuf, &cbRead);
     1446    if (RT_SUCCESS(rc))
     1447        *pcbRead = cbRead;
     1448
     1449    return rc;
     1450}
     1451
    14311452RTDECL(int) RTJsonParseFromBuf(PRTJSONVAL phJsonVal, const uint8_t *pbBuf, size_t cbBuf, PRTERRINFO pErrInfo)
    14321453{
     
    14911512        }
    14921513        RTStrmClose(Args.u.hStream);
     1514    }
     1515
     1516    return rc;
     1517}
     1518
     1519RTDECL(int) RTJsonParseFromVfsFile(PRTJSONVAL phJsonVal, RTVFSFILE hVfsFile, PRTERRINFO pErrInfo)
     1520{
     1521    AssertPtrReturn(phJsonVal, VERR_INVALID_POINTER);
     1522    AssertReturn(hVfsFile != NIL_RTVFSFILE, VERR_INVALID_POINTER);
     1523
     1524    int rc = VINF_SUCCESS;
     1525    RTJSONREADERARGS Args;
     1526    RTJSONTOKENIZER Tokenizer;
     1527
     1528    Args.cbData   = 0;
     1529    Args.u.hVfsFile = hVfsFile;
     1530    rc = rtJsonTokenizerInit(&Tokenizer, rtJsonTokenizerParseFromVfsFile, &Args, pErrInfo);
     1531    if (RT_SUCCESS(rc))
     1532    {
     1533        rc = rtJsonParse(&Tokenizer, phJsonVal);
     1534        rtJsonTokenizerDestroy(&Tokenizer);
    14931535    }
    14941536
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette