diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2026-02-27 22:37:31 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2026-02-27 22:37:31 +0100 |
| commit | f7a6fd9a6efd7a603e534242f3aa21e782a61958 (patch) | |
| tree | eb442cdbdc2e21593d2acc2659328f09e97cb5a9 | |
| parent | c5b3eb06fd0fd4f1f29b5c76c1b8865c55b88ea9 (diff) | |
feat: moving checksum to sources directory, update file structure.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
| -rw-r--r-- | CMakeLists.txt | 4 | ||||
| -rw-r--r-- | example/fix_tag_example/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | example/fix_tag_example/example.cpp | 2 | ||||
| -rw-r--r-- | include/ocl/fix/checksum.hpp | 30 | ||||
| -rw-r--r-- | src/fix/checksum.cpp | 44 | ||||
| -rw-r--r-- | src/fix/parser.cpp (renamed from src/fix/parser_impl.cpp) | 4 | ||||
| -rw-r--r-- | src/test/.keep | 0 |
7 files changed, 54 insertions, 32 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 66d9997..ddc301a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,11 +5,11 @@ project(ocl_fix) find_package(Boost REQUIRED core) -add_library(ocl_fix src/fix/parser_impl.cpp) +add_library(ocl_fix src/fix/parser.cpp src/fix/checksum.cpp) target_link_libraries(ocl_fix Boost::core) target_include_directories(ocl_fix PUBLIC ${BOOST_INCLUDE_DIRS}) -install(DIRECTORY include/ DESTINATION include) +install(DIRECTORY include DESTINATION include) install(TARGETS ocl_fix DESTINATION lib) set_property(TARGET ocl_fix PROPERTY CXX_STANDARD 20) diff --git a/example/fix_tag_example/CMakeLists.txt b/example/fix_tag_example/CMakeLists.txt index 967ca07..ebf3e6f 100644 --- a/example/fix_tag_example/CMakeLists.txt +++ b/example/fix_tag_example/CMakeLists.txt @@ -13,4 +13,4 @@ target_include_directories(FixExample PUBLIC ${BOOST_INCLUDE_DIRS}) set_property(TARGET FixExample PROPERTY CXX_STANDARD 20) target_include_directories(FixExample PUBLIC ../../include/ocl) -target_link_libraries(FixExample PRIVATE ocl_fix.a) +target_link_libraries(FixExample PUBLIC ocl_fix.a) diff --git a/example/fix_tag_example/example.cpp b/example/fix_tag_example/example.cpp index efd66f8..42b859f 100644 --- a/example/fix_tag_example/example.cpp +++ b/example/fix_tag_example/example.cpp @@ -45,7 +45,7 @@ int main(int argc, char** argv) ocl::io::print(":value=", fix["49"], "\n"); ocl::io::print(":checksum=", ocl::fix::try_index_checksum(fix), "\n"); - ocl::io::print(":checksum=", ocl::fix::operators::checksum(default_fix_unchecked), "\n"); + //ocl::io::print(":checksum=", ocl::fix::operators::checksum(default_fix_unchecked), "\n"); return 0; } diff --git a/include/ocl/fix/checksum.hpp b/include/ocl/fix/checksum.hpp index 2672996..5d9fa8b 100644 --- a/include/ocl/fix/checksum.hpp +++ b/include/ocl/fix/checksum.hpp @@ -18,42 +18,20 @@ namespace ocl::fix /// \brief Returns the checksum index of a FIX message. /// \param range the range_buffer containing the message. /// \throws runtime_error if the FIX message is invalid (missing tag "8"). - - inline std::string try_index_checksum(range_buffer& fix) - { - if (fix.is_valid()) - return fix["10"]; - else - ::ocl::fix::detail::throw_runtime_error(); - - ::ocl::fix::detail::unreachable(); - - return {}; - } + std::string try_index_checksum(range_buffer& fix); /// \brief FIX message operators namespace. namespace operators { - + using checksum_type = long long; /// \brief Calculates the FIX protocol checksum for a message. /// \param in_ Pointer to the message buffer. /// \param len Length of the message in bytes. /// \return The checksum value (sum of all bytes modulo 256). - constexpr inline checksum_type - checksum(const std::string_view& in_) noexcept - { - checksum_type cks{}; - - for (std::size_t idx{}; - idx < in_.size(); ++idx) - cks += static_cast<uint8_t>(in_[idx]); - - // add \0 - cks += 1; - return cks % 256; - } + checksum_type + checksum(const boost::string_view& in_) noexcept; } // namespace operators diff --git a/src/fix/checksum.cpp b/src/fix/checksum.cpp new file mode 100644 index 0000000..e8e155f --- /dev/null +++ b/src/fix/checksum.cpp @@ -0,0 +1,44 @@ +/* + * File: fix/checksum.cpp + * Purpose: Financial Information Exchange parser in C++ + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2026, Amlal El Mahrouss, licensed under the Boost Software License. + */ + +#include <ocl/fix/checksum.hpp> + +namespace ocl::fix +{ + + std::string try_index_checksum(range_buffer& fix) + { + if (fix.is_valid()) + return fix["10"]; + else + detail::throw_runtime_error(); + + detail::unreachable(); + + return {}; + } + + namespace operators + { + + checksum_type + checksum(const boost::string_view& in_) noexcept + { + checksum_type cks{}; + + for (std::size_t idx{}; + idx < in_.size(); ++idx) + cks += static_cast<uint8_t>(in_[idx]); + + // add \0 + cks += 1; + return cks % 256; + } + + } // namespace operators + +} // namespace ocl::fix diff --git a/src/fix/parser_impl.cpp b/src/fix/parser.cpp index 4db9873..d12056b 100644 --- a/src/fix/parser_impl.cpp +++ b/src/fix/parser.cpp @@ -1,5 +1,5 @@ /* - * File: fix/parser_impl.cpp + * File: fix/parser.cpp * Purpose: Financial Information Exchange parser in C++ * Author: Amlal El Mahrouss (amlal@nekernel.org) * Copyright 2025-2026, Amlal El Mahrouss, licensed under the Boost Software License. @@ -84,7 +84,7 @@ namespace ocl::fix visitor::visitor() = default; visitor::~visitor() = default; - /// \brief Alias of visit. + /// @brief Alias of visit. range_buffer visitor::operator()(const std::string& in) { return impl_->visit(in.data()); diff --git a/src/test/.keep b/src/test/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/test/.keep |
