From 172e95811568ba994d014e2f98c2fcb09b9f4016 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Mon, 20 Jan 2025 18:20:02 +0000 Subject: [PATCH 1/4] replace utf-8 errors --- src/clp_ffi_js/ir/StructuredIrStreamReader.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/clp_ffi_js/ir/StructuredIrStreamReader.cpp b/src/clp_ffi_js/ir/StructuredIrStreamReader.cpp index f12b66b4..9f23902b 100644 --- a/src/clp_ffi_js/ir/StructuredIrStreamReader.cpp +++ b/src/clp_ffi_js/ir/StructuredIrStreamReader.cpp @@ -132,7 +132,8 @@ auto StructuredIrStreamReader::decode_range(size_t begin_idx, size_t end_idx, bo ); json_str = std::string(cEmptyJsonStr); } else { - json_str = json_result.value().dump(); + json_str = json_result.value() + .dump(-1, ' ', false, nlohmann::detail::error_handler_t::replace); } return json_str; }; From d643d424a9ae8367f1dc7dc34d42080a7a143f7f Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Mon, 20 Jan 2025 18:47:26 +0000 Subject: [PATCH 2/4] fix lint --- src/clp_ffi_js/ir/StructuredIrStreamReader.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/clp_ffi_js/ir/StructuredIrStreamReader.cpp b/src/clp_ffi_js/ir/StructuredIrStreamReader.cpp index 9f23902b..a1ef1e8c 100644 --- a/src/clp_ffi_js/ir/StructuredIrStreamReader.cpp +++ b/src/clp_ffi_js/ir/StructuredIrStreamReader.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include From 9bd54f78242f69212709c6418edc923fbf1cdf77 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Mon, 20 Jan 2025 19:30:09 +0000 Subject: [PATCH 3/4] add code --- src/clp_ffi_js/ir/StructuredIrStreamReader.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/clp_ffi_js/ir/StructuredIrStreamReader.cpp b/src/clp_ffi_js/ir/StructuredIrStreamReader.cpp index a1ef1e8c..8fd917a8 100644 --- a/src/clp_ffi_js/ir/StructuredIrStreamReader.cpp +++ b/src/clp_ffi_js/ir/StructuredIrStreamReader.cpp @@ -27,6 +27,20 @@ namespace { constexpr std::string_view cEmptyJsonStr{"{}"}; constexpr std::string_view cReaderOptionsLogLevelKey{"logLevelKey"}; constexpr std::string_view cReaderOptionsTimestampKey{"timestampKey"}; + +/** + * @see nlohmann::basic_json::dump + * Dumps a JSON value with error handling set to replace invalid UTF-8 characters rather than + * throwing an exception. + * @param json + * @return Serialized JSON. + */ +auto json_dump_with_replace(nlohmann::json const& json) -> std::string; + +auto json_dump_with_replace(nlohmann::json const& json) -> std::string { + return json.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace); +} + } // namespace auto StructuredIrStreamReader::create( @@ -133,8 +147,7 @@ auto StructuredIrStreamReader::decode_range(size_t begin_idx, size_t end_idx, bo ); json_str = std::string(cEmptyJsonStr); } else { - json_str = json_result.value() - .dump(-1, ' ', false, nlohmann::detail::error_handler_t::replace); + json_str = json_dump_with_replace(json_result.value()); } return json_str; }; From 2a8e0a668c3ae1f2eea1a2bfba2bd0b4c563d823 Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Mon, 20 Jan 2025 19:39:05 +0000 Subject: [PATCH 4/4] junhao review --- src/clp_ffi_js/ir/StructuredIrStreamReader.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/clp_ffi_js/ir/StructuredIrStreamReader.cpp b/src/clp_ffi_js/ir/StructuredIrStreamReader.cpp index 8fd917a8..67370067 100644 --- a/src/clp_ffi_js/ir/StructuredIrStreamReader.cpp +++ b/src/clp_ffi_js/ir/StructuredIrStreamReader.cpp @@ -30,14 +30,14 @@ constexpr std::string_view cReaderOptionsTimestampKey{"timestampKey"}; /** * @see nlohmann::basic_json::dump - * Dumps a JSON value with error handling set to replace invalid UTF-8 characters rather than + * Serializes a JSON value into a string with invalid UTF-8 sequences replaced rather than * throwing an exception. * @param json * @return Serialized JSON. */ -auto json_dump_with_replace(nlohmann::json const& json) -> std::string; +auto dump_json_with_replace(nlohmann::json const& json) -> std::string; -auto json_dump_with_replace(nlohmann::json const& json) -> std::string { +auto dump_json_with_replace(nlohmann::json const& json) -> std::string { return json.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace); } @@ -147,7 +147,7 @@ auto StructuredIrStreamReader::decode_range(size_t begin_idx, size_t end_idx, bo ); json_str = std::string(cEmptyJsonStr); } else { - json_str = json_dump_with_replace(json_result.value()); + json_str = dump_json_with_replace(json_result.value()); } return json_str; };