|
19 | 19 | #define itkWasmStringStream_h
|
20 | 20 |
|
21 | 21 | #include "itkWasmDataObject.h"
|
22 |
| -#include "rapidjson/document.h" |
23 | 22 | #include <string_view>
|
24 | 23 |
|
25 | 24 | #include "WebAssemblyInterfaceExport.h"
|
26 | 25 |
|
| 26 | +#include "glaze/glaze.hpp" |
| 27 | + |
27 | 28 | namespace itk
|
28 | 29 | {
|
| 30 | + |
| 31 | +struct StringStreamJSON |
| 32 | +{ |
| 33 | + std::string data; |
| 34 | + size_t size; |
| 35 | +}; |
| 36 | + |
29 | 37 | /**
|
30 | 38 | *\class WasmStringStream
|
31 | 39 | * \brief JSON representation for a std::stringstream
|
@@ -74,15 +82,17 @@ class WebAssemblyInterface_EXPORT WasmStringStream : public WasmDataObject
|
74 | 82 | void SetJSON(const char * jsonChar) override
|
75 | 83 | {
|
76 | 84 | std::string json(jsonChar);
|
77 |
| - rapidjson::Document document; |
78 |
| - if (document.Parse(json.c_str()).HasParseError()) |
79 |
| - { |
80 |
| - throw std::runtime_error("Could not parse JSON"); |
81 |
| - } |
82 |
| - const rapidjson::Value & dataJson = document["data"]; |
83 |
| - const std::string dataString( dataJson.GetString() ); |
| 85 | + std::string deserialized; |
| 86 | + auto deserializedAttempt = glz::read_json<StringStreamJSON>(json); |
| 87 | + if (!deserializedAttempt) |
| 88 | + { |
| 89 | + const std::string descriptiveError = glz::format_error(deserializedAttempt, json); |
| 90 | + throw std::runtime_error("Failed to deserialize StringStreamJSON: " + descriptiveError); |
| 91 | + } |
| 92 | + auto stringStream = deserializedAttempt.value(); |
| 93 | + const std::string dataString = stringStream.data; |
84 | 94 | const char * dataPtr = reinterpret_cast< char * >( std::strtoull(dataString.substr(35).c_str(), nullptr, 10) );
|
85 |
| - size_t size = document["size"].GetInt(); |
| 95 | + size_t size = stringStream.size; |
86 | 96 | const std::string_view string(dataPtr, size);
|
87 | 97 | m_StringStream.str(std::string{string});
|
88 | 98 |
|
|
0 commit comments