summaryrefslogtreecommitdiffhomepage
path: root/include/ocl/fix
diff options
context:
space:
mode:
Diffstat (limited to 'include/ocl/fix')
-rw-r--r--include/ocl/fix/checksum.hpp12
-rw-r--r--include/ocl/fix/detail/config.hpp21
-rw-r--r--include/ocl/fix/parser.hpp28
3 files changed, 56 insertions, 5 deletions
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