VirtualBox

Ignore:
Timestamp:
Aug 29, 2018 3:09:34 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
124685
Message:

IPRT/rest: Added RTJsonIteratorBeginArray and RTJsonIteratorBeginObject for more accurate JSON decoding. Early RTCRestArray implementation. bugref:9167

Location:
trunk/src/VBox/Runtime/common/rest
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/rest/RTCRestOutputToString.cpp

    r73879 r73956  
    3535
    3636
    37 RTCRestOutputToString::RTCRestOutputToString(RTCString *a_pDst)
     37RTCRestOutputToString::RTCRestOutputToString(RTCString *a_pDst, bool a_fAppend /*= false*/)
    3838    : m_pDst(a_pDst)
    3939    , m_fOutOfMemory(false)
    4040{
     41    if (!a_fAppend)
     42        m_pDst->setNull();
    4143}
    4244
  • trunk/src/VBox/Runtime/common/rest/RTCRestStringMapBase.cpp

    r73951 r73956  
    115115     */
    116116    RTJSONIT hIterator;
    117     int rcRet = RTJsonIteratorBegin(a_rCursor.m_hValue, &hIterator);
     117    int rcRet = RTJsonIteratorBeginObject(a_rCursor.m_hValue, &hIterator);
    118118    if (RT_SUCCESS(rcRet))
    119119    {
     
    176176        rcRet = a_rCursor.m_pPrimary->addError(a_rCursor, rcRet, "RTJsonIteratorBegin failed: %Rrc", rcRet);
    177177    return rcRet;
    178 
    179178}
    180179
    181180// later?
    182 //    virtual int RTCRestStringMapBase::toString(RTCString *a_pDst, uint32_t a_fFlags = 0) const ;
     181//    virtual int RTCRestStringMapBase::toString(RTCString *a_pDst, uint32_t a_fFlags = kCollectionFormat_Unspecified) const ;
    183182//    virtual int RTCRestStringMapBase::fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL,
    184183//                           uint32_t a_fFlags = kCollectionFormat_Unspecified) ;
  • trunk/src/VBox/Runtime/common/rest/rest-primary-object-types.cpp

    r73933 r73956  
    5959int RTCRestObjectBase::toString(RTCString *a_pDst, uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) const
    6060{
    61     Assert(a_fFlags == kCollectionFormat_Unspecified); RT_NOREF(a_fFlags);
    62 
    6361    /*
    6462     * Just wrap the JSON serialization method.
    6563     */
    66     RTCRestOutputToString Tmp(a_pDst);
     64    RTCRestOutputToString Tmp(a_pDst, RT_BOOL(a_fFlags & kToString_Append));
    6765    serializeAsJson(Tmp);
    6866    return Tmp.finalize() ? VINF_SUCCESS : VERR_NO_MEMORY;
     
    8179                                  uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/)
    8280{
    83     Assert(a_fFlags == kCollectionFormat_Unspecified); RT_NOREF(a_fFlags);
     81    RT_NOREF(a_fFlags);
    8482
    8583    /*
     
    185183int RTCRestBool::toString(RTCString *a_pDst, uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) const
    186184{
    187     Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
    188 
     185    if (!(a_fFlags & kToString_Append))
     186    {
     187        if (m_fValue)
     188            return a_pDst->assignNoThrow(RT_STR_TUPLE("true"));
     189        return a_pDst->assignNoThrow(RT_STR_TUPLE("false"));
     190    }
    189191    if (m_fValue)
    190         return a_pDst->assignNoThrow(RT_STR_TUPLE("true"));
    191     return a_pDst->assignNoThrow(RT_STR_TUPLE("false"));
     192        return a_pDst->appendNoThrow(RT_STR_TUPLE("true"));
     193    return a_pDst->appendNoThrow(RT_STR_TUPLE("false"));
    192194}
    193195
     
    196198                            uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/)
    197199{
    198     Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
     200    RT_NOREF(a_fFlags);
     201
    199202    if (a_rValue.startsWithWord("true", RTCString::CaseInsensitive))
    200203        m_fValue = true;
     
    299302int RTCRestInt64::toString(RTCString *a_pDst, uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) const
    300303{
    301     Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
    302 
    303     return a_pDst->printfNoThrow("%RI64", m_iValue);
     304    if (!(a_fFlags & kToString_Append))
     305        return a_pDst->printfNoThrow("%RI64", m_iValue);
     306    return a_pDst->appendPrintfNoThrow("%RI64", m_iValue);
    304307}
    305308
     
    308311                             uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/)
    309312{
    310     Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
     313    RT_NOREF(a_fFlags);
    311314
    312315    int rc = RTStrToInt64Full(RTStrStripL(a_rValue.c_str()), 10, &m_iValue);
     
    415418int RTCRestInt32::toString(RTCString *a_pDst, uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) const
    416419{
    417     Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
    418 
    419     return a_pDst->printfNoThrow("%RI32", m_iValue);
     420    if (!(a_fFlags & kToString_Append))
     421        return a_pDst->printfNoThrow("%RI32", m_iValue);
     422    return a_pDst->appendPrintfNoThrow("%RI32", m_iValue);
    420423}
    421424
     
    424427                             uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/)
    425428{
    426     Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
     429    RT_NOREF(a_fFlags);
    427430
    428431    int rc = RTStrToInt32Full(RTStrStripL(a_rValue.c_str()), 10, &m_iValue);
     
    531534int RTCRestInt16::toString(RTCString *a_pDst, uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) const
    532535{
    533     Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
    534 
    535     return a_pDst->printfNoThrow("%RI16", m_iValue);
     536    if (!(a_fFlags & kToString_Append))
     537        return a_pDst->printfNoThrow("%RI16", m_iValue);
     538    return a_pDst->appendPrintfNoThrow("%RI16", m_iValue);
    536539}
    537540
     
    540543                             uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/)
    541544{
    542     Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
     545    RT_NOREF(a_fFlags);
    543546
    544547    int rc = RTStrToInt16Full(RTStrStripL(a_rValue.c_str()), 10, &m_iValue);
     
    626629int RTCRestDouble::toString(RTCString *a_pDst, uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) const
    627630{
    628     Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
    629 
    630631    /* Just a simple approximation here. */
    631632    /** @todo implement floating point values for json. */
     
    638639    size_t const cchValue = strlen(szValue);
    639640
    640     return a_pDst->assignNoThrow(szValue, cchValue);
     641    if (!(a_fFlags & kToString_Append))
     642        return a_pDst->assignNoThrow(szValue, cchValue);
     643    return a_pDst->appendNoThrow(szValue, cchValue);
    641644}
    642645
     
    645648                              uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/)
    646649{
    647     Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
     650    RT_NOREF(a_fFlags);
    648651
    649652    const char *pszValue = RTStrStripL(a_rValue.c_str());
     
    751754int RTCRestString::toString(RTCString *a_pDst, uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/) const
    752755{
    753     Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
    754 
    755     return a_pDst->assignNoThrow(*this);
     756    if (!(a_fFlags & kToString_Append))
     757        return a_pDst->assignNoThrow(*this);
     758    return a_pDst->appendNoThrow(*this);
    756759}
    757760
     
    760763                              uint32_t a_fFlags /*= kCollectionFormat_Unspecified*/)
    761764{
    762     Assert(a_fFlags == 0); RT_NOREF(a_fFlags);
    763     RT_NOREF(a_pszName); RT_NOREF(a_pErrInfo);
     765    RT_NOREF(a_fFlags); RT_NOREF(a_pszName); RT_NOREF(a_pErrInfo);
    764766
    765767    return assignNoThrow(a_rValue);
Note: See TracChangeset for help on using the changeset viewer.

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