| 32 | //----------------------------------------------------------------------------- |
| 33 | |
| 34 | SimObject* TamlJSONReader::read( FileStream& stream ) |
| 35 | { |
| 36 | // Debug Profiling. |
| 37 | PROFILE_SCOPE(TamlJSONReader_Read); |
| 38 | |
| 39 | // Read JSON file. |
| 40 | const U32 streamSize = stream.getStreamSize(); |
| 41 | FrameTemp<char> jsonText( streamSize + 1 ); |
| 42 | if ( !stream.read( streamSize, jsonText ) ) |
| 43 | { |
| 44 | // Warn! |
| 45 | Con::warnf("TamlJSONReader::read() - Could not load Taml JSON file from stream."); |
| 46 | return NULL; |
| 47 | } |
| 48 | jsonText[streamSize] = '\0'; |
| 49 | |
| 50 | // Create JSON document. |
| 51 | rapidjson::Document document; |
| 52 | document.Parse<0>( jsonText ); |
| 53 | |
| 54 | // Check the document is valid. |
| 55 | if ( document.GetType() != rapidjson::kObjectType ) |
| 56 | { |
| 57 | // Warn! |
| 58 | Con::warnf("TamlJSONReader::read() - Load Taml JSON file from stream but was invalid."); |
| 59 | return NULL; |
| 60 | } |
| 61 | |
| 62 | // Parse root value. |
| 63 | SimObject* pSimObject = parseType( document.MemberBegin() ); |
| 64 | |
| 65 | // Reset parse. |
| 66 | resetParse(); |
| 67 | |
| 68 | return pSimObject; |
| 69 | } |
| 70 | |
| 71 | //----------------------------------------------------------------------------- |
| 72 |
no test coverage detected