in AzureSphereSquirrel/HLCore/json.cpp [394:454]
SQInteger JSON::encodeObject(HSQUIRRELVM vm, HSQOBJECT object, SQChar *&jsonString, SQInteger &jsonStringStorageSize, SQInteger &jsonStringSize, SQInteger depth)
{
// Determine if we've recursed too deep,
// we're likely in a cicular reference and risk a stack overflow.
if(depth > JSON_MAX_ENCODE_DEPTH)
{
return sq_throwerror(vm, "Maximum encode depth reached");
}
// Determine the type of the object to encode
switch(sq_type(object))
{
case OT_TABLE:
case OT_CLASS:
if(SQ_FAILED(encodeClassTable(vm, object, jsonString, jsonStringStorageSize, jsonStringSize, depth)))
{
return SQ_ERROR;
}
break;
case OT_ARRAY:
if(SQ_FAILED(encodeArray(vm, object, jsonString, jsonStringStorageSize, jsonStringSize, depth)))
{
return SQ_ERROR;
}
break;
case OT_STRING:
if(SQ_FAILED(encodeString(vm, object, jsonString, jsonStringStorageSize, jsonStringSize, depth)))
{
return SQ_ERROR;
}
break;
case OT_INTEGER:
case OT_FLOAT:
if(SQ_FAILED(encodeNumber(vm, object, jsonString, jsonStringStorageSize, jsonStringSize, depth)))
{
return SQ_ERROR;
}
break;
case OT_BOOL:
if(SQ_FAILED(encodeBool(vm, object, jsonString, jsonStringStorageSize, jsonStringSize, depth)))
{
return SQ_ERROR;
}
break;
case OT_NULL:
if(SQ_FAILED(encodeNull(vm, object, jsonString, jsonStringStorageSize, jsonStringSize, depth)))
{
return SQ_ERROR;
}
break;
case OT_INSTANCE:
if(SQ_FAILED(encodeInstance(vm, object, jsonString, jsonStringStorageSize, jsonStringSize, depth)))
{
return SQ_ERROR;
}
break;
default: return sq_throwerror(vm, "Unserializable object encountered");
}
return SQ_OK;
}