diff --git a/src/clp_ffi_js/ir/StreamReader.cpp b/src/clp_ffi_js/ir/StreamReader.cpp index 98e5cb84..f41d79ff 100644 --- a/src/clp_ffi_js/ir/StreamReader.cpp +++ b/src/clp_ffi_js/ir/StreamReader.cpp @@ -1,6 +1,5 @@ #include "StreamReader.hpp" -#include #include #include #include @@ -167,29 +166,27 @@ auto StreamReader::create(DataArrayTsType const& data_array, ReaderOptions const // Validate the stream's version auto pos = zstd_decompressor->get_pos(); auto const version{get_version(*zstd_decompressor)}; - if (std::ranges::find(cUnstructuredIrVersions, version) != cUnstructuredIrVersions.end()) { - try { + auto const version_validation_result{clp::ffi::ir_stream::validate_protocol_version(version)}; + + try { + if (clp::ffi::ir_stream::IRProtocolErrorCode::Supported == version_validation_result) { + zstd_decompressor->seek_from_begin(0); + return std::make_unique(StructuredIrStreamReader::create( + std::move(zstd_decompressor), + std::move(data_buffer), + reader_options + )); + } + if (clp::ffi::ir_stream::IRProtocolErrorCode::BackwardCompatible + == version_validation_result) + { zstd_decompressor->seek_from_begin(pos); - } catch (ZstdDecompressor::OperationFailed& e) { - throw ClpFfiJsException{ - clp::ErrorCode::ErrorCode_Failure, - __FILENAME__, - __LINE__, - std::format("Unable to rewind zstd decompressor: {}", e.what()) - }; + return std::make_unique(UnstructuredIrStreamReader::create( + std::move(zstd_decompressor), + std::move(data_buffer) + )); } - return std::make_unique(UnstructuredIrStreamReader::create( - std::move(zstd_decompressor), - std::move(data_buffer) - )); - } - // if (clp::ffi::ir_stream::IRProtocolErrorCode_Supported - // == clp::ffi::ir_stream::validate_protocol_version(version)) - // { - // FIXME: wait for https://github.com/y-scope/clp/pull/573 - try { - zstd_decompressor->seek_from_begin(0); - } catch (ZstdDecompressor::OperationFailed& e) { + } catch (ZstdDecompressor::OperationFailed const& e) { throw ClpFfiJsException{ clp::ErrorCode::ErrorCode_Failure, __FILENAME__, @@ -197,18 +194,12 @@ auto StreamReader::create(DataArrayTsType const& data_array, ReaderOptions const std::format("Unable to rewind zstd decompressor: {}", e.what()) }; } - return std::make_unique(StructuredIrStreamReader::create( - std::move(zstd_decompressor), - std::move(data_buffer), - reader_options - )); - // } - - // throw ClpFfiJsException{ - // clp::ErrorCode::ErrorCode_Unsupported, - // __FILENAME__, - // __LINE__, - // std::format("Unable to create reader for IR stream with version {}.", version) - // }; + + throw ClpFfiJsException{ + clp::ErrorCode::ErrorCode_Unsupported, + __FILENAME__, + __LINE__, + std::format("Unable to create reader for IR stream with version {}.", version) + }; } } // namespace clp_ffi_js::ir diff --git a/src/clp_ffi_js/ir/StreamReader.hpp b/src/clp_ffi_js/ir/StreamReader.hpp index 111b110f..51b1e23a 100644 --- a/src/clp_ffi_js/ir/StreamReader.hpp +++ b/src/clp_ffi_js/ir/StreamReader.hpp @@ -1,10 +1,8 @@ #ifndef CLP_FFI_JS_IR_STREAMREADER_HPP #define CLP_FFI_JS_IR_STREAMREADER_HPP -#include #include #include -#include #include #include @@ -19,9 +17,6 @@ EMSCRIPTEN_DECLARE_VAL_TYPE(ReaderOptions); EMSCRIPTEN_DECLARE_VAL_TYPE(DecodedResultsTsType); EMSCRIPTEN_DECLARE_VAL_TYPE(FilteredLogEventMapTsType); -constexpr std::array cUnstructuredIrVersions - = {"v0.0.2", "v0.0.1", "v0.0.0", "0.0.2", "0.0.1", "0.0.0"}; - /** * Class to deserialize and decode Zstandard-compressed CLP IR streams as well as format decoded * log events.