diff --git a/src/server/sparkd/orderman/utils/fix_order_codec.cpp b/src/server/sparkd/orderman/utils/fix_order_codec.cpp new file mode 100644 index 000000000..1122e6661 --- /dev/null +++ b/src/server/sparkd/orderman/utils/fix_order_codec.cpp @@ -0,0 +1 @@ +#include "fix_order_codec.h" diff --git a/src/server/sparkd/orderman/utils/fix_order_codec.h b/src/server/sparkd/orderman/utils/fix_order_codec.h new file mode 100644 index 000000000..81908ff5a --- /dev/null +++ b/src/server/sparkd/orderman/utils/fix_order_codec.h @@ -0,0 +1,49 @@ +#pragma once + +#include +#include + +#include "orderman_utils.h" +#include "server/sparkd/jetfix/codec/i32_toa.h" +#include "server/sparkd/jetfix/codec/MessageDefinitions.h" +#include "lib/utils/bts_assert.h" + +namespace bts { +namespace api {class Security;} + +namespace orderman { + +constexpr int clordid_sz() {return 20;} +constexpr int price_sz() {return 20;} +constexpr int quantity_sz() {return 6;} + +inline void encode_clorid(OrderKey ok, SecurityKey sk,std::string *out) { + u32_toa(sk.value(),&((*out)[0]),clordid_sz()/2); + u32_toa(ok.value(),&((*out)[clordid_sz()/2]),clordid_sz()/2); +} + +inline void decode_clorid(std::string const&in, OrderKey *ok, SecurityKey *sk) +{ + bts_assert(in.size() == clordid_sz()); + char buffer[clordid_sz()/2+1]; + buffer[clordid_sz()/2] = 0; + + std::memcpy(buffer,&in[0],clordid_sz()/2); + *sk = SecurityKey(std::atoi(buffer)); + + std::memcpy(buffer,&in[clordid_sz()/2],clordid_sz()/2); + *ok = OrderKey(std::atoi(buffer)); +} + +template +OrderKey get_order_key(MSG const &msg) +{ + + bts_assert(msg.template has ()); + OrderKey result; + SecurityKey dummy; + decode_clorid(msg.template get(),&result,&dummy); + return result; +} + +}} diff --git a/src/server/sparkd/orderman/utils/orderman_utils.cpp b/src/server/sparkd/orderman/utils/orderman_utils.cpp new file mode 100644 index 000000000..3e1e0e1a5 --- /dev/null +++ b/src/server/sparkd/orderman/utils/orderman_utils.cpp @@ -0,0 +1,6 @@ +#include "orderman_utils.h" + +namespace bts { +namespace orderman { + +}} diff --git a/src/server/sparkd/orderman/utils/orderman_utils.h b/src/server/sparkd/orderman/utils/orderman_utils.h new file mode 100644 index 000000000..9680eb1d5 --- /dev/null +++ b/src/server/sparkd/orderman/utils/orderman_utils.h @@ -0,0 +1,65 @@ +#pragma once + +#include +#include +#include +#include + +#include "lib/utils/ValueWrapper.h" +#include "lib/domain_model/common.h" +#include "lib/utils/bts_assert.h" + +namespace bts { +namespace api {class Security;} +namespace orderman { +using OrderKey = utils::ValueWrapper; +using FIXSessionName = utils::ValueWrapper; +using GatewayName = utils::ValueWrapper; +using OperatorID = utils::ValueWrapper>; +using ExchangeOrderID = utils::ValueWrapper>; +using OrderTimeStamp = utils::ValueWrapper> ; +using SecurityPtr = const api::Security *; +using AccountName = utils::ValueWrapper>; + +template void to_array(std::string const&str,std::array*out ) +{ + auto &result = *out; + bts_assert(str.size() <= N); + memset(&result[0],' ', N); + memcpy(&result[0],str.data(),str.size()); +} + +template void to_str(std::array const&in ,std::string *out) +{ + auto &result = *out; + result.resize(N); + memcpy(&result[0],in.data(),N); +} + +template +T to(std::string const&str) +{ + T result; + to_array(str,&result.value()); + return result; +} + +template +inline std::string to_str (T const&t) +{ + std::string result; + to_str(t.value(),&result); + return result; +} + +template +std::pair to_trim_str(std::array const&in) +{ + for (auto i = (size_t) 0; i < N; i++) + if (in[i] == ' ') + return std::make_pair (&in[0],i); + return std::make_pair (&in[0],N); +} + +}} +