diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2026-01-11 15:39:31 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2026-01-11 15:39:31 +0100 |
| commit | 20f36d5bb5f30ba759676fde1a4da0579e66a878 (patch) | |
| tree | a2281d502c527945869a03897e9f8760bedf59aa | |
| parent | d0decd01ec7c9e3f3d493cc6aa9ec87fd34a6722 (diff) | |
feat: FIX library improvements, prepping release.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | example/fix_tag_example/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | example/fix_tag_example/example.cpp | 27 | ||||
| -rw-r--r-- | include/ocl/fix/checksum.hpp | 12 | ||||
| -rw-r--r-- | include/ocl/fix/detail/config.hpp | 21 | ||||
| -rw-r--r-- | include/ocl/fix/parser.hpp | 28 | ||||
| -rw-r--r-- | src/fix/parser_impl.cpp | 7 |
7 files changed, 78 insertions, 19 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1829925..19ca3fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ find_package(Boost REQUIRED) add_library(ocl_fix src/fix/parser_impl.cpp) target_link_libraries(ocl_fix boost_core) +target_include_directories(ocl_fix PUBLIC ${BOOST_INCLUDE_DIRS}) install(DIRECTORY include/ DESTINATION include) install(TARGETS ocl_fix DESTINATION lib) diff --git a/example/fix_tag_example/CMakeLists.txt b/example/fix_tag_example/CMakeLists.txt index 56afa24..ca6d6dd 100644 --- a/example/fix_tag_example/CMakeLists.txt +++ b/example/fix_tag_example/CMakeLists.txt @@ -9,6 +9,7 @@ project( find_package(Boost REQUIRED) add_executable(FixExample example.cpp) +target_include_directories(FixExample PUBLIC ${BOOST_INCLUDE_DIRS}) set_property(TARGET FixExample PROPERTY CXX_STANDARD 20) target_include_directories(FixExample PUBLIC ../../include/ocl) diff --git a/example/fix_tag_example/example.cpp b/example/fix_tag_example/example.cpp index cb758c2..efd66f8 100644 --- a/example/fix_tag_example/example.cpp +++ b/example/fix_tag_example/example.cpp @@ -1,3 +1,8 @@ +// Copyright 2025-2026, Amlal El Mahrouss (amlal@nekernel.org) +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// Official repository: https://github.com/ocl-org/fix + #include <ocl/fix/parser.hpp> #include <ocl/fix/checksum.hpp> @@ -15,18 +20,16 @@ constexpr char const default_fix[] = { }; constexpr char default_fix_unchecked[] = { - '8', '=', 'F', 'I', 'X', '.', '4', '.', '2', 0x01, - '9', '=', '8', '0', 0x01, // BodyLength = 80 - '3', '5', '=', 'A', 0x01, - '4', '9', '=', 'S', 'E', 'R', 'V', 'E', 'R', 0x01, - '5', '6', '=', 'C', 'L', 'I', 'E', 'N', 'T', 0x01, - '3', '4', '=', '1', '7', '7', 0x01, - '5', '2', '=', '2', '0', '0', '9', '0', '1', '0', '7', '-', '1', '8', ':', '1', '5', ':', '1', '6', 0x01, - '9', '8', '=', '0', 0x01, - '1', '0', '8', '=', '3', '0', 0x01, - 0x00 -}; - + '8', '=', 'F', 'I', 'X', '.', '4', '.', '2', 0x01, + '9', '=', '8', '0', 0x01, // BodyLength = 80 + '3', '5', '=', 'A', 0x01, + '4', '9', '=', 'S', 'E', 'R', 'V', 'E', 'R', 0x01, + '5', '6', '=', 'C', 'L', 'I', 'E', 'N', 'T', 0x01, + '3', '4', '=', '1', '7', '7', 0x01, + '5', '2', '=', '2', '0', '0', '9', '0', '1', '0', '7', '-', '1', '8', ':', '1', '5', ':', '1', '6', 0x01, + '9', '8', '=', '0', 0x01, + '1', '0', '8', '=', '3', '0', 0x01, + 0x00}; int main(int argc, char** argv) { diff --git a/include/ocl/fix/checksum.hpp b/include/ocl/fix/checksum.hpp index 6492acf..a5e4469 100644 --- a/include/ocl/fix/checksum.hpp +++ b/include/ocl/fix/checksum.hpp @@ -18,12 +18,17 @@ 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 - detail::throw_runtime_error(); + ::ocl::fix::detail::throw_runtime_error(); + + ::ocl::fix::detail::unreachable(); + + return {}; } /// \brief FIX message operators namespace. @@ -41,9 +46,8 @@ namespace ocl::fix checksum_type cks{}; for (std::size_t idx{}; - idx < in_.size(); ++idx) - cks += static_cast<uint8_t>(in_[idx]); - + idx < in_.size(); ++idx) + cks += static_cast<uint8_t>(in_[idx]); // add \0 cks += 1; diff --git a/include/ocl/fix/detail/config.hpp b/include/ocl/fix/detail/config.hpp index 0568f90..b73454e 100644 --- a/include/ocl/fix/detail/config.hpp +++ b/include/ocl/fix/detail/config.hpp @@ -12,4 +12,25 @@ #include <ocl/crc_hash.hpp> #include <ocl/print.hpp> +namespace ocl::fix::detail +{ + + inline void throw_runtime_error(const boost::source_location& location = BOOST_CURRENT_LOCATION) + { + throw std::runtime_error(location.to_string()); + } + + inline void unreachable() noexcept + { +#if defined(__GNUC__) || defined(__clang__) + __builtin_unreachable(); +#elif defined(_MSC_VER) + __assume(false); +#else + std::abort(); +#endif + } + +} // namespace ocl::fix::detail + #endif diff --git a/include/ocl/fix/parser.hpp b/include/ocl/fix/parser.hpp index ceba660..9268662 100644 --- a/include/ocl/fix/parser.hpp +++ b/include/ocl/fix/parser.hpp @@ -5,10 +5,16 @@ * Copyright 2025, Amlal El Mahrouss, licensed under the Boost Software License. */ +// Copyright 2025-2026, Amlal El Mahrouss (amlal@nekernel.org) +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// Official repository: https://github.com/ocl-org/fix + #ifndef __OCL_FIX_PARSER #define __OCL_FIX_PARSER #include <ocl/fix/detail/config.hpp> +#include <fstream> #include <string> #include <memory> @@ -52,6 +58,14 @@ namespace ocl::fix return std::string(range.bytes_, range.length_); } + inline std::string to_string(const range& range) noexcept + { + if (range.length_ < 1) + return std::string{}; + + return std::string(range.bytes_, range.length_); + } + /// @brief a range object containing the FIX packet values. class range_buffer final { @@ -60,7 +74,7 @@ namespace ocl::fix std::string magic_{}; string_hash_map<value_type> message_{}; - static inline const char* begin; + static boost::string_view& begin; explicit range_buffer() = default; ~range_buffer() = default; @@ -120,4 +134,16 @@ namespace ocl::fix } // namespace ocl::fix +inline std::ostream& operator<<(std::ostream& os, ocl::fix::range& r) +{ + os << ocl::fix::to_string(r); + return os; +} + +inline std::ostream& operator<<(std::ostream& os, const ocl::fix::range& r) +{ + os << ocl::fix::to_string(r); + return os; +} + #endif // ifndef __OCL_FIX_PARSER diff --git a/src/fix/parser_impl.cpp b/src/fix/parser_impl.cpp index b776dcd..27ea01d 100644 --- a/src/fix/parser_impl.cpp +++ b/src/fix/parser_impl.cpp @@ -13,10 +13,13 @@ namespace ocl::fix namespace detail { - inline const char* begin_fix() noexcept + + inline boost::string_view& begin_fix() noexcept { - return "FIX.4.2"; + static boost::string_view begin_fix{"FIX.4.2"}; + return begin_fix; } + } // namespace detail struct visitor::impl final |
