summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-07-05 20:49:28 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-07-05 20:49:28 +0200
commit028c97404da7ad9ebcbcd9c97903f28e0da222ed (patch)
tree8db275898d1d6540d29fcfc23eba88c2d49b4a65
parent49d96f61fca89046036454cdd1a5c965277c1740 (diff)
feat: fix: `fix.hpp` engine parser.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
-rw-r--r--examples/equiv/equiv.cc1
-rw-r--r--examples/fix/CMakeLists.txt12
-rw-r--r--examples/fix/fix.cc25
-rw-r--r--lib/cgi.hpp6
-rw-r--r--lib/crc32.hpp6
-rw-r--r--lib/embdfs.hpp6
-rw-r--r--lib/equiv.hpp4
-rw-r--r--lib/fix.hpp82
-rw-r--r--lib/io/print.hpp6
-rw-r--r--lib/opt.hpp6
10 files changed, 112 insertions, 42 deletions
diff --git a/examples/equiv/equiv.cc b/examples/equiv/equiv.cc
index 664602e..1b7b042 100644
--- a/examples/equiv/equiv.cc
+++ b/examples/equiv/equiv.cc
@@ -5,6 +5,7 @@
*/
#include <lib/equiv.hpp>
+#include <lib/fix.hpp>
#include <iostream>
/* finally test it */
diff --git a/examples/fix/CMakeLists.txt b/examples/fix/CMakeLists.txt
new file mode 100644
index 0000000..db8921b
--- /dev/null
+++ b/examples/fix/CMakeLists.txt
@@ -0,0 +1,12 @@
+
+cmake_minimum_required(VERSION 3.15...3.31)
+
+project(
+ Fix
+ VERSION 1.0
+ LANGUAGES CXX)
+
+add_executable(Fix fix.cc)
+
+set_property(TARGET Fix PROPERTY CXX_STANDARD 20)
+target_include_directories(Fix PUBLIC ../../)
diff --git a/examples/fix/fix.cc b/examples/fix/fix.cc
new file mode 100644
index 0000000..1ab258e
--- /dev/null
+++ b/examples/fix/fix.cc
@@ -0,0 +1,25 @@
+/*
+ string checksum example
+ written by Amlal El Mahrouss.
+ licensed under the MIT license
+ */
+
+#include <lib/fix.hpp>
+#include <iostream>
+
+/* finally test it */
+int main(int argc, char** argv)
+{
+ snu::fix::fix_visitor visitor;
+ auto fix = visitor.visit("8=FIX.4.2|9=65|35=A|49=SERVER|56=CLIENT|34=177|52=20090107-18:15:16|98=0|108=30|10=062|");
+
+ std::cout << "magic: " << fix.msg_magic_ << std::endl;
+
+ for (auto fields : fix.msg_body_)
+ {
+ std::cout << "key: " << fields.first;
+ std::cout << ",value: " << fields.second << std::endl;
+ }
+
+ return 0;
+}
diff --git a/lib/cgi.hpp b/lib/cgi.hpp
index 86fc6f9..e171eed 100644
--- a/lib/cgi.hpp
+++ b/lib/cgi.hpp
@@ -4,8 +4,8 @@
* Copyright 2023-2025, Amlal El Mahrouss all rights reserved.
*/
-#ifndef _STDX_CGI_HPP
-#define _STDX_CGI_HPP
+#ifndef _SNU_CGI_HPP
+#define _SNU_CGI_HPP
#include <cstdio>
#include <string>
@@ -59,4 +59,4 @@ namespace snu
} // namespace web
} // namespace snu
-#endif // ifndef _STDX_CGI_HPP \ No newline at end of file
+#endif // ifndef _SNU_CGI_HPP \ No newline at end of file
diff --git a/lib/crc32.hpp b/lib/crc32.hpp
index 726626e..bbdb15c 100644
--- a/lib/crc32.hpp
+++ b/lib/crc32.hpp
@@ -5,8 +5,8 @@
* Copyright 2025, Amlal El Mahrouss all rights reserved.
*/
-#ifndef _STDX_CRC32_HPP
-#define _STDX_CRC32_HPP
+#ifndef _SNU_CRC32_HPP
+#define _SNU_CRC32_HPP
#include <cstdint>
#include <cstddef>
@@ -71,4 +71,4 @@ namespace snu
} // namespace details
} // namespace snu
-#endif // !_STDX_CRC32_HPP \ No newline at end of file
+#endif // !_SNU_CRC32_HPP \ No newline at end of file
diff --git a/lib/embdfs.hpp b/lib/embdfs.hpp
index af6118a..9ec82d4 100644
--- a/lib/embdfs.hpp
+++ b/lib/embdfs.hpp
@@ -5,8 +5,8 @@
* Copyright 2025, Amlal El Mahrouss all rights reserved.
*/
-#ifndef _STDX_EMBDFS_HPP
-#define _STDX_EMBDFS_HPP
+#ifndef _SNU_EMBDFS_HPP
+#define _SNU_EMBDFS_HPP
#include <cstdint>
#include <cstddef>
@@ -74,4 +74,4 @@ namespace snu::embdfs
} // namespace details
} // namespace snu::embdfs
-#endif // ifndef _STDX_EMBDFS_HPP \ No newline at end of file
+#endif // ifndef _SNU_EMBDFS_HPP \ No newline at end of file
diff --git a/lib/equiv.hpp b/lib/equiv.hpp
index 15512f4..14fe280 100644
--- a/lib/equiv.hpp
+++ b/lib/equiv.hpp
@@ -1,8 +1,8 @@
/*
* File: equiv.hpp
- * Purpose: equivalence runtime c++ header.
+ * Purpose: Equivalence runtime c++ header.
* Author: Amlal El Mahrouss (founder@snu.systems)
- * Copyright 2025, Amlal El Mahrouss all rights reserved.
+ * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp all rights reserved.
*/
#pragma once
diff --git a/lib/fix.hpp b/lib/fix.hpp
index c458b18..4620ad0 100644
--- a/lib/fix.hpp
+++ b/lib/fix.hpp
@@ -2,23 +2,23 @@
* File: fix.hpp
* Purpose: Financial Information Protocol implementation in C++.
* Author: Amlal El Mahrouss (founder@snu.systems)
- * Copyright 2025, Amlal El Mahrouss all rights reserved.
+ * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp all rights reserved.
*/
-#ifndef _STDX_FIX_HPP
-#define _STDX_FIX_HPP
+#ifndef _SNU_FIX_HPP
+#define _SNU_FIX_HPP
#include <cstdint>
#include <cstddef>
#include <cassert>
+#include <utility>
+#include <vector>
#include <string>
#include <arpa/inet.h>
#include <sys/socket.h>
namespace snu::fix
{
- struct fix_reader;
- struct fix_writer;
struct fix_visitor;
struct fix_range;
struct fix_range_data;
@@ -43,26 +43,58 @@ namespace snu::fix
class fix_range_data final
{
- private:
- friend fix_visitor;
-
- std::string begin_string_;
- size_t body_len_;
- uint16_t msg_type_;
- uint32_t msg_seq_num_;
- uint32_t sender_comp_id_;
- uint32_t target_comp_id_;
- std::string send_time_;
- std::string ci_ord_id_;
- uint16_t side_;
- uint16_t security_type_;
- std::string symbol_;
- uint32_t order_qty_;
- uint16_t order_type_;
- uint64_t price_;
- uint64_t time_in_force_;
- uint32_t checksum_;
+ public:
+ std::string msg_magic_;
+ std::size_t msg_body_len_;
+ std::vector<std::pair<std::string, std::string>> 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 _STDX_FIX_HPP
+#endif // ifndef _SNU_FIX_HPP
diff --git a/lib/io/print.hpp b/lib/io/print.hpp
index c8c21e8..0a5b5e2 100644
--- a/lib/io/print.hpp
+++ b/lib/io/print.hpp
@@ -5,8 +5,8 @@
* Copyright 2025, SNU Systems Corp all rights reserved.
*/
-#ifndef _STDX_PRINT_HPP
-#define _STDX_PRINT_HPP
+#ifndef _SNU_PRINT_HPP
+#define _SNU_PRINT_HPP
#include <iostream>
@@ -26,4 +26,4 @@ namespace snu
}
} // namespace snu
-#endif // ifndef _STDX_PRINT_HPP \ No newline at end of file
+#endif // ifndef _SNU_PRINT_HPP \ No newline at end of file
diff --git a/lib/opt.hpp b/lib/opt.hpp
index 2c9405d..1145f19 100644
--- a/lib/opt.hpp
+++ b/lib/opt.hpp
@@ -4,8 +4,8 @@
* Copyright 2023-2025, Amlal El Mahrouss/SNU Systems Corp all rights reserved.
*/
-#ifndef _STDX_OPT_HPP
-#define _STDX_OPT_HPP
+#ifndef _SNU_OPT_HPP
+#define _SNU_OPT_HPP
#include <stdexcept>
#include <utility>
@@ -108,4 +108,4 @@ namespace snu
} /* namespace snu */
-#endif /* ifndef _STDX_OPT_HPP */
+#endif /* ifndef _SNU_OPT_HPP */