| 152 | } |
| 153 | |
| 154 | template <ScriptContext context> void EncodeJSONArray( |
| 155 | SQArray* arr, |
| 156 | rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>>* obj, |
| 157 | rapidjson::MemoryPoolAllocator<SourceAllocator>& allocator) |
| 158 | { |
| 159 | for (int i = 0; i < arr->_usedSlots; i++) |
| 160 | { |
| 161 | SQObject* node = &arr->_values[i]; |
| 162 | |
| 163 | rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>> newObj(rapidjson::kObjectType); |
| 164 | rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>> newArray(rapidjson::kArrayType); |
| 165 | |
| 166 | switch (node->_Type) |
| 167 | { |
| 168 | case OT_STRING: |
| 169 | obj->PushBack(rapidjson::StringRef(node->_VAL.asString->_val), allocator); |
| 170 | break; |
| 171 | case OT_INTEGER: |
| 172 | obj->PushBack(node->_VAL.asInteger, allocator); |
| 173 | break; |
| 174 | case OT_FLOAT: |
| 175 | obj->PushBack(node->_VAL.asFloat, allocator); |
| 176 | break; |
| 177 | case OT_BOOL: |
| 178 | if (node->_VAL.asInteger) |
| 179 | obj->PushBack(rapidjson::StringRef("true"), allocator); |
| 180 | else |
| 181 | obj->PushBack(rapidjson::StringRef("false"), allocator); |
| 182 | break; |
| 183 | case OT_TABLE: |
| 184 | EncodeJSONTable<context>(node->_VAL.asTable, &newObj, allocator); |
| 185 | obj->PushBack(newObj, allocator); |
| 186 | break; |
| 187 | case OT_ARRAY: |
| 188 | EncodeJSONArray<context>(node->_VAL.asArray, &newArray, allocator); |
| 189 | obj->PushBack(newArray, allocator); |
| 190 | break; |
| 191 | default: |
| 192 | spdlog::info("SQ encode Json type {} not supported", SQTypeNameFromID(node->_Type)); |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | ADD_SQFUNC( |
| 198 | "table", |
nothing calls this directly
no test coverage detected