From 1d3e2b0146d01cb57bb80e55bb033f47fa63daf1 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 5 Jul 2025 20:51:26 +0200 Subject: feat: `fix/` directory category. Signed-off-by: Amlal El Mahrouss --- lib/fix.hpp | 100 -------------------------------------------------- lib/fix/parser.hpp | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 100 deletions(-) delete mode 100644 lib/fix.hpp create mode 100644 lib/fix/parser.hpp (limited to 'lib') diff --git a/lib/fix.hpp b/lib/fix.hpp deleted file mode 100644 index 4620ad0..0000000 --- a/lib/fix.hpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * File: fix.hpp - * Purpose: Financial Information Protocol implementation in C++. - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp all rights reserved. - */ - -#ifndef _SNU_FIX_HPP -#define _SNU_FIX_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace snu::fix -{ - struct fix_visitor; - struct fix_range; - struct fix_range_data; - - /// @brief Buffer+Length structure - typedef fix_range* fix_range_ptr_t; - - struct fix_range final - { - char* ascii_bytes_; - uint16_t length_; - }; - - /// @brief Convert range to usable string. - inline std::string to_string(fix_range& range) noexcept - { - if (range.length_ < 0) - return ""; - - return std::string(range.ascii_bytes_, range.length_); - } - - class fix_range_data final - { - public: - std::string msg_magic_; - std::size_t msg_body_len_; - std::vector> msg_body_; - }; - - class fix_visitor final - { - public: - static constexpr auto soh = '|'; - static constexpr auto base = 10U; - - fix_range_data visit(const std::string& in) - { - fix_range_data ret{}; - - std::string in_tmp; - - try - { - for (auto& ch : in) - { - if (ch != soh) - { - in_tmp += ch; - continue; - } - - auto key = in_tmp.substr(0, in_tmp.find("=")); - auto val = in_tmp.substr(in_tmp.find("=") + 1); - - if (ret.msg_magic_.empty()) - { - ret.msg_magic_ = val; - } - else - { - ret.msg_body_.emplace_back(std::make_pair(key, val)); - ret.msg_body_len_ += in_tmp.size(); - } - - in_tmp.clear(); - } - } - catch (...) - { - return {}; - } - - return ret; - } - }; -} // namespace snu::fix - -#endif // ifndef _SNU_FIX_HPP diff --git a/lib/fix/parser.hpp b/lib/fix/parser.hpp new file mode 100644 index 0000000..83bbd1a --- /dev/null +++ b/lib/fix/parser.hpp @@ -0,0 +1,106 @@ +/* + * File: fix.hpp + * Purpose: Financial Information Protocol implementation in C++. + * Author: Amlal El Mahrouss (founder@snu.systems) + * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp all rights reserved. + */ + +#ifndef _SNU_FIX_HPP +#define _SNU_FIX_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace snu::fix +{ + struct fix_visitor; + struct fix_range; + struct fix_range_data; + + /// @brief Buffer+Length structure + typedef fix_range* fix_range_ptr_t; + + struct fix_range final + { + char* ascii_bytes_; + uint16_t length_; + }; + + /// @brief Convert range to usable string. + inline std::string to_string(fix_range& range) noexcept + { + if (range.length_ < 0) + return ""; + + return std::string(range.ascii_bytes_, range.length_); + } + + class fix_range_data final + { + public: + std::string msg_magic_; + std::size_t msg_body_len_; + std::vector> msg_body_; + }; + + class fix_visitor final + { + public: + static constexpr auto soh = '|'; + static constexpr auto base = 10U; + + explicit fix_visitor() = default; + ~fix_visitor() = default; + + fix_visitor& operator=(const fix_visitor&) = default; + fix_visitor(const fix_visitor&) = default; + + fix_range_data visit(const std::string& in) + { + fix_range_data ret{}; + + std::string in_tmp; + + try + { + for (auto& ch : in) + { + if (ch != soh) + { + in_tmp += ch; + continue; + } + + auto key = in_tmp.substr(0, in_tmp.find("=")); + auto val = in_tmp.substr(in_tmp.find("=") + 1); + + if (ret.msg_magic_.empty()) + { + ret.msg_magic_ = val; + } + else + { + ret.msg_body_.emplace_back(std::make_pair(key, val)); + ret.msg_body_len_ += in_tmp.size(); + } + + in_tmp.clear(); + } + } + catch (...) + { + return {}; + } + + return ret; + } + }; +} // namespace snu::fix + +#endif // ifndef _SNU_FIX_HPP -- cgit v1.2.3