Пример #1
0
VError VJSONBinaryWriter::StreamValue(const VJSONValue& inValue, VMemoryBuffer<>& outBuff)
{
	VError err = VE_OK;
	sBYTE btype = (sBYTE)inValue.GetType();
	outBuff.AddData(&btype, 1);
	switch( inValue.GetType())
	{
		case JSON_null:
		case JSON_undefined:
		case JSON_true:
		case JSON_false:
			{
				break;
			}
			
		case JSON_string:
			{
				const VInlineString* s = &(inValue.fString);
				sLONG len = (sLONG)s->GetLength();
				outBuff.AddData(&len, 4);
				if (len > 0)
					outBuff.AddData(s->GetCPointer(), len * 2);
				break;
			}

		case JSON_date:
			{
				outBuff.AddData(&inValue.fTimeStamp, sizeof(sLONG8));
				break;
			}

		case JSON_number:
			{
				outBuff.AddData(&inValue.fNumber, sizeof(Real));
				break;
			}

		case JSON_array:
			{
				err = StreamArray( inValue.GetArray(), outBuff);
				break;
			}

		case JSON_object:
			{
				err = StreamObject( inValue.GetObject(), outBuff);
				break;
			}
		
		default:
			xbox_assert( false);
	}
	
	return err;
}
Пример #2
0
VError VJSONWriter::StringifyValue( const VJSONValue& inValue, VString& outString)
{
    VError err = VE_OK;
    switch( inValue.GetType())
    {
    case JSON_undefined:
    {
        outString = VJSONValue::sUndefinedString;
        break;
    }

    case JSON_null:
    {
        outString = VJSONValue::sNullString;
        break;
    }

    case JSON_true:
    {
        outString = VJSONValue::sTrueString;
        break;
    }

    case JSON_false:
    {
        outString = VJSONValue::sFalseString;
        break;
    }

    case JSON_string:
    {
        VString s;
        err = inValue.GetString( s);
        s.GetJSONString( outString, GetOptions());
        break;
    }

    case JSON_number:
    {
        VReal r( inValue.GetNumber());
        err = r.GetJSONString( outString, GetOptions());
        break;
    }

    case JSON_array:
    {
        err = StringifyArray( inValue.GetArray(), outString);
        break;
    }

    case JSON_object:
    {
        err = StringifyObject( inValue.GetObject(), outString);
        break;
    }

    default:
        xbox_assert( false);
    }

    return err;
}
Пример #3
0
VError VJSONWriter::StringifyValue( const VJSONValue& inValue, VString& outString)
{
	VError err = VE_OK;
	switch( inValue.GetType())
	{
		case JSON_undefined:
			{
				outString = VJSONValue::sUndefinedString;
				break;
			}

		case JSON_null:
			{
				outString = VJSONValue::sNullString;
				break;
			}

		case JSON_true:
			{
				outString = VJSONValue::sTrueString;
				break;
			}

		case JSON_false:
			{
				outString = VJSONValue::sFalseString;
				break;
			}
			
		case JSON_string:
			{
				VString s;
				err = inValue.GetString( s);
				s.GetJSONString( outString, GetOptions());
				break;
			}

		case JSON_date:
			{
				VTime dd;
				VString s;
				inValue.GetTime(dd);
				dd.GetJSONString(s);
				if ((GetOptions() & JSON_AllowDates) != 0)
				{
					outString = "\"!!" + s + "!!\"";
				}
				else
					outString = "\"" + s + "\"";
				break;
			}

		case JSON_number:
			{
				VReal r( inValue.GetNumber());
				err = r.GetJSONString( outString, GetOptions());
				break;
			}

		case JSON_array:
			{
				err = StringifyArray( inValue.GetArray(), outString);
				break;
			}

		case JSON_object:
			{
				err = StringifyObject( inValue.GetObject(), outString);
				break;
			}
		
		default:
			xbox_assert( false);
	}
	
	return err;
}