| 101 | } |
| 102 | |
| 103 | template <ScriptContext context> void EncodeJSONTable( |
| 104 | SQTable* table, |
| 105 | rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>>* obj, |
| 106 | rapidjson::MemoryPoolAllocator<SourceAllocator>& allocator) |
| 107 | { |
| 108 | for (int i = 0; i < table->_numOfNodes; i++) |
| 109 | { |
| 110 | SQTable::_HashNode* node = &table->_nodes[i]; |
| 111 | if (node->key._Type == OT_STRING) |
| 112 | { |
| 113 | rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>> newObj(rapidjson::kObjectType); |
| 114 | rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<SourceAllocator>> newArray(rapidjson::kArrayType); |
| 115 | |
| 116 | switch (node->val._Type) |
| 117 | { |
| 118 | case OT_STRING: |
| 119 | obj->AddMember( |
| 120 | rapidjson::StringRef(node->key._VAL.asString->_val), rapidjson::StringRef(node->val._VAL.asString->_val), allocator); |
| 121 | break; |
| 122 | case OT_INTEGER: |
| 123 | obj->AddMember(rapidjson::StringRef(node->key._VAL.asString->_val), node->val._VAL.asInteger, allocator); |
| 124 | break; |
| 125 | case OT_FLOAT: |
| 126 | obj->AddMember(rapidjson::StringRef(node->key._VAL.asString->_val), node->val._VAL.asFloat, allocator); |
| 127 | break; |
| 128 | case OT_BOOL: |
| 129 | if (node->val._VAL.asInteger) |
| 130 | { |
| 131 | obj->AddMember(rapidjson::StringRef(node->key._VAL.asString->_val), true, allocator); |
| 132 | } |
| 133 | else |
| 134 | { |
| 135 | obj->AddMember(rapidjson::StringRef(node->key._VAL.asString->_val), false, allocator); |
| 136 | } |
| 137 | break; |
| 138 | case OT_TABLE: |
| 139 | EncodeJSONTable<context>(node->val._VAL.asTable, &newObj, allocator); |
| 140 | obj->AddMember(rapidjson::StringRef(node->key._VAL.asString->_val), newObj, allocator); |
| 141 | break; |
| 142 | case OT_ARRAY: |
| 143 | EncodeJSONArray<context>(node->val._VAL.asArray, &newArray, allocator); |
| 144 | obj->AddMember(rapidjson::StringRef(node->key._VAL.asString->_val), newArray, allocator); |
| 145 | break; |
| 146 | default: |
| 147 | spdlog::warn("SQ_EncodeJSON: squirrel type {} not supported", SQTypeNameFromID(node->val._Type)); |
| 148 | break; |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | template <ScriptContext context> void EncodeJSONArray( |
| 155 | SQArray* arr, |
nothing calls this directly
no test coverage detected