VirtualBox

Changeset 74028 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Sep 2, 2018 2:56:38 PM (6 years ago)
Author:
vboxsync
Message:

IPRT/rest: Implemented RTCRestDouble::deserializeFromJson(). bugref:9167

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/rest/rest-primary-object-types.cpp

    r74027 r74028  
    876876
    877877        /* Just a simple approximation here. */
    878         /** @todo implement floating point values for json. */
     878        /** @todo Not 100% sure printf %g produces the right result for JSON floating point, but it'll have to do for now... */
    879879        char szValue[128];
    880880#ifdef _MSC_VER
     
    893893int RTCRestDouble::deserializeFromJson(RTCRestJsonCursor const &a_rCursor)
    894894{
    895     AssertMsgFailed(("RTJson needs to be taught double values."));
    896     /** @todo implement floating point values for json. */
    897     return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_NOT_IMPLEMENTED, "double is not supported yet");
     895    m_rdValue = 0.0;
     896    m_fNullIndicator = false;
     897
     898    RTJSONVALTYPE enmType = RTJsonValueGetType(a_rCursor.m_hValue);
     899    if (enmType == RTJSONVALTYPE_NUMBER)
     900    {
     901        int rc = RTJsonValueQueryNumber(a_rCursor.m_hValue, &m_rdValue);
     902        if (RT_SUCCESS(rc))
     903            return rc;
     904        return a_rCursor.m_pPrimary->addError(a_rCursor, rc, "RTJsonValueQueryNumber failed with %Rrc", rc);
     905    }
     906
     907    if (enmType == RTJSONVALTYPE_INTEGER)
     908    {
     909        int64_t iTmp = 0;
     910        int rc = RTJsonValueQueryInteger(a_rCursor.m_hValue, &iTmp);
     911        if (RT_SUCCESS(rc))
     912        {
     913            m_rdValue = iTmp;
     914            if (m_rdValue == iTmp)
     915                return rc;
     916            return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_OUT_OF_RANGE, "value %RI64 does not fit in a double", iTmp);
     917        }
     918        return a_rCursor.m_pPrimary->addError(a_rCursor, rc, "RTJsonValueQueryInteger failed with %Rrc", rc);
     919    }
     920
     921    if (enmType == RTJSONVALTYPE_NULL)
     922    {
     923        m_fNullIndicator = true;
     924        return VINF_SUCCESS;
     925    }
     926
     927    /* This is probably non-sense... */
     928    if (enmType == RTJSONVALTYPE_TRUE)
     929        m_rdValue = 1.0;
     930
     931    return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_WRONG_TYPE, "wrong JSON type %s for a double",
     932                                          RTJsonValueTypeName(RTJsonValueGetType(a_rCursor.m_hValue)));
    898933}
    899934
     
    904939    {
    905940        /* Just a simple approximation here. */
    906         /** @todo implement floating point values for json. */
     941        /** @todo Not 100% sure printf %g produces the right result for JSON floating point, but it'll have to do for now... */
    907942        char szValue[128];
    908943#ifdef _MSC_VER
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