-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor StreamReader to modularize decoding logic.
- Loading branch information
1 parent
e4fda3e
commit 3dae806
Showing
5 changed files
with
96 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "decoding_methods.hpp" | ||
|
||
#include <clp/ErrorCode.hpp> | ||
#include <clp/ffi/ir_stream/decoding_methods.hpp> | ||
#include <clp/ReaderInterface.hpp> | ||
#include <clp/TraceableException.hpp> | ||
#include <spdlog/spdlog.h> | ||
|
||
#include <clp_ffi_js/ClpFfiJsException.hpp> | ||
|
||
namespace clp_ffi_js::ir { | ||
auto rewind_reader_and_verify_encoding_type(clp::ReaderInterface& reader) -> void { | ||
reader.seek_from_begin(0); | ||
|
||
bool is_four_bytes_encoding{true}; | ||
if (auto const err{clp::ffi::ir_stream::get_encoding_type(reader, is_four_bytes_encoding)}; | ||
clp::ffi::ir_stream::IRErrorCode::IRErrorCode_Success != err) | ||
{ | ||
SPDLOG_CRITICAL("Failed to decode encoding type, err={}", err); | ||
throw ClpFfiJsException{ | ||
clp::ErrorCode::ErrorCode_MetadataCorrupted, | ||
__FILENAME__, | ||
__LINE__, | ||
"Failed to decode encoding type." | ||
}; | ||
} | ||
if (false == is_four_bytes_encoding) { | ||
throw ClpFfiJsException{ | ||
clp::ErrorCode::ErrorCode_Unsupported, | ||
__FILENAME__, | ||
__LINE__, | ||
"IR stream uses unsupported encoding." | ||
}; | ||
} | ||
} | ||
} // namespace clp_ffi_js::ir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef CLP_FFI_JS_IR_DECODING_METHODS_HPP | ||
#define CLP_FFI_JS_IR_DECODING_METHODS_HPP | ||
|
||
#include <clp/ReaderInterface.hpp> | ||
|
||
namespace clp_ffi_js::ir { | ||
auto rewind_reader_and_verify_encoding_type(clp::ReaderInterface& reader) -> void; | ||
} // namespace clp_ffi_js::ir | ||
|
||
#endif // CLP_FFI_JS_IR_DECODING_METHODS_HPP |