Skip to content

Commit

Permalink
Use version checking utility from CLP FFI.
Browse files Browse the repository at this point in the history
  • Loading branch information
junhaoliao committed Nov 7, 2024
1 parent d870b19 commit edda4b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 40 deletions.
61 changes: 26 additions & 35 deletions src/clp_ffi_js/ir/StreamReader.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "StreamReader.hpp"

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <format>
Expand Down Expand Up @@ -167,48 +166,40 @@ 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>(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>(UnstructuredIrStreamReader::create(
std::move(zstd_decompressor),
std::move(data_buffer)
));
}
return std::make_unique<UnstructuredIrStreamReader>(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__,
__LINE__,
std::format("Unable to rewind zstd decompressor: {}", e.what())
};
}
return std::make_unique<StructuredIrStreamReader>(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
5 changes: 0 additions & 5 deletions src/clp_ffi_js/ir/StreamReader.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#ifndef CLP_FFI_JS_IR_STREAMREADER_HPP
#define CLP_FFI_JS_IR_STREAMREADER_HPP

#include <array>
#include <cstddef>
#include <memory>
#include <string_view>

#include <clp/streaming_compression/zstd/Decompressor.hpp>
#include <emscripten/val.h>
Expand All @@ -19,9 +17,6 @@ EMSCRIPTEN_DECLARE_VAL_TYPE(ReaderOptions);
EMSCRIPTEN_DECLARE_VAL_TYPE(DecodedResultsTsType);
EMSCRIPTEN_DECLARE_VAL_TYPE(FilteredLogEventMapTsType);

constexpr std::array<std::string_view, 6> 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.
Expand Down

0 comments on commit edda4b3

Please sign in to comment.