summaryrefslogtreecommitdiffhomepage
path: root/include/ocl
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2026-01-01 12:52:28 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2026-01-01 12:52:28 +0100
commit665e433697247c4a43e055830dee7a72afdb810f (patch)
tree48d87bd8d7b54d739757463e4b6ea41f9736c329 /include/ocl
parent44209bcfee561efb73fbe0c27373f5f8d55c6046 (diff)
feat: FIX Checksum API for OCL.FIX.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'include/ocl')
-rw-r--r--include/ocl/fix/checksum.hpp43
1 files changed, 42 insertions, 1 deletions
diff --git a/include/ocl/fix/checksum.hpp b/include/ocl/fix/checksum.hpp
index c075b13..31aee75 100644
--- a/include/ocl/fix/checksum.hpp
+++ b/include/ocl/fix/checksum.hpp
@@ -9,9 +9,50 @@
#define __OCL_FIX_CHECKSUM
#include <ocl/fix/detail/config.hpp>
+#include <ocl/fix/parser.hpp>
+#include <boost/core/detail/string_view.hpp>
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();
+ }
+
+ /// \brief FIX message operators namespace.
+ namespace operators::fix
+ {
+ 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).
+ inline checksum_type
+ checksum(const char* in_,
+ const long len)
+ {
+ if (len < 1)
+ return 0L;
+
+ long long cks{};
+
+ for (long idx{}; idx < len; ++idx)
+ {
+ cks += static_cast<unsigned char>(in_[idx]);
+ }
+
+ return cks % 256;
+ }
+ } // namespace operators::fix
+
+} // namespace ocl::fix
#endif