c2
This commit is contained in:
1 parent
a43070f812
commit
b68c963b5e
2 files changed
+68
-28
No files matched your search
@@ -17,7 +17,7 @@ struct ActionableEventAnalyzer {
|
||||
uint64_t time_from_last_transaction;
|
||||
};
|
||||
std::vector<Event> events;
|
||||
template <class M> void operator()(MDP3PacketHeader const&ph,MDP3MessageHeader const &, const M &m) {
|
||||
template <class M> void operator()(MDP3PacketHeader const&ph,MDP3MsgHeader const &, const M &m) {
|
||||
Event e{m.transactTime(), ph.sending_time, 0,
|
||||
ph.sending_time - m.transactTime(), 0};
|
||||
if (events.size()) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../util/meta_type_pack.h"
|
||||
#include "mdp3_gen/AdminHeartbeat12.h"
|
||||
#include "mdp3_gen/AdminLogin15.h"
|
||||
#include "mdp3_gen/AdminLogout16.h"
|
||||
@@ -30,7 +31,6 @@
|
||||
#include "mdp3_gen/SnapshotFullRefresh52.h"
|
||||
#include "mdp3_gen/SnapshotFullRefreshOrderBook44.h"
|
||||
#include "mdp3_gen/SnapshotFullRefreshOrderBook53.h"
|
||||
#include "../../util/meta_type_pack.h"
|
||||
|
||||
#include "lib/utils/bts_assert.h"
|
||||
|
||||
@@ -44,7 +44,7 @@ struct __attribute__((__packed__)) MDP3PacketHeader {
|
||||
uint64_t sending_time;
|
||||
};
|
||||
|
||||
struct __attribute__((__packed__)) MDP3MessageHeader {
|
||||
struct __attribute__((__packed__)) MDP3MsgHeader {
|
||||
uint16_t msg_size;
|
||||
uint16_t block_length;
|
||||
uint16_t template_id;
|
||||
@@ -52,40 +52,84 @@ struct __attribute__((__packed__)) MDP3MessageHeader {
|
||||
uint16_t version;
|
||||
};
|
||||
|
||||
struct __attribute__((__packed__)) MDP3Msg {
|
||||
MDP3MessageHeader message_header;
|
||||
std::array<char, std::numeric_limits<uint16_t>::max()> payload;
|
||||
class MDP3Msg {
|
||||
public:
|
||||
MDP3MsgHeader const &header() const { return _header; }
|
||||
std::string_view payload() const {
|
||||
return {(char const *)&_header + sizeof(MDP3MsgHeader),
|
||||
_header.msg_size - sizeof(MDP3MsgHeader)};
|
||||
}
|
||||
|
||||
private:
|
||||
const MDP3MsgHeader _header;
|
||||
};
|
||||
|
||||
class MDP3MsgIterator {
|
||||
public:
|
||||
MDP3MsgIterator(MDP3Msg const *message) : message(message) {}
|
||||
|
||||
MDP3MsgIterator &operator++() {
|
||||
message =
|
||||
(MDP3Msg *)(((uint8_t *)message) + message->header().msg_size);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator!=(MDP3MsgIterator other) const {
|
||||
return message != other.message;
|
||||
}
|
||||
|
||||
MDP3Msg const &operator*() { return *message; }
|
||||
MDP3Msg const *operator->() { return message; }
|
||||
|
||||
private:
|
||||
MDP3Msg const *message;
|
||||
};
|
||||
|
||||
struct MDP3PacketView {
|
||||
MDP3PacketView(std::string_view packet_bytes) : bytes(packet_bytes) {}
|
||||
MDP3PacketHeader const &header() const {
|
||||
return *((MDP3PacketHeader *)bytes.data());
|
||||
}
|
||||
|
||||
MDP3MsgIterator begin() const {
|
||||
return (MDP3Msg *)(bytes.data() + sizeof(MDP3PacketHeader));
|
||||
}
|
||||
|
||||
MDP3MsgIterator end() const {
|
||||
return (MDP3Msg *)(bytes.data() + bytes.size());
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string_view bytes;
|
||||
};
|
||||
|
||||
class MDP3Parser {
|
||||
public:
|
||||
MDP3Parser() {
|
||||
for (auto &h : handlers)
|
||||
h = [](auto const&,auto const &) {};
|
||||
h = [](auto const &, auto const &) {};
|
||||
}
|
||||
|
||||
void on_bytes(std::string_view const &bytes) {
|
||||
bts_assert_d(bytes.size() >=
|
||||
sizeof(spartan::MDP3PacketHeader) + sizeof(MDP3MessageHeader));
|
||||
auto packet_header = (MDP3PacketHeader*) bytes.data();
|
||||
spartan::MDP3Msg *msg =
|
||||
(spartan::MDP3Msg *)(bytes.data() + sizeof(MDP3PacketHeader));
|
||||
while (((void *)msg) < (bytes.data() + bytes.size())) {
|
||||
handlers[msg->message_header.template_id](*packet_header,*msg);
|
||||
msg = (spartan::MDP3Msg *)((uint8_t *)msg + msg->message_header.msg_size);
|
||||
}
|
||||
MDP3PacketView packet(bytes);
|
||||
|
||||
for (auto const &msg : packet)
|
||||
handlers[msg.header().template_id](packet.header(), msg);
|
||||
}
|
||||
|
||||
|
||||
template <class T, class C> void set_handler(C &c) {
|
||||
handlers[T::sbeTemplateId()] = [&c](auto const&packet_header,auto const &msg) {
|
||||
c(packet_header,T{(char *)msg.payload.data(), msg.payload.size()});
|
||||
handlers[T::sbeTemplateId()] = [&c](auto const &packet_header,
|
||||
auto const &msg) {
|
||||
c(packet_header, T{(char *)msg.payload().data(), msg.payload().size()});
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
std::array<std::function<void(MDP3PacketHeader const&,spartan::MDP3Msg const &)>,
|
||||
std::numeric_limits<uint16_t>::max()>
|
||||
std::array<
|
||||
std::function<void(MDP3PacketHeader const &, spartan::MDP3Msg const &)>,
|
||||
std::numeric_limits<uint16_t>::max()>
|
||||
handlers;
|
||||
};
|
||||
|
||||
@@ -116,14 +160,10 @@ using ForAllMDP3Types = meta_type_pack<
|
||||
mdp3::MDIncrementalRefreshSessionStatistics51,
|
||||
mdp3::MDIncrementalRefreshTradeSummary42,
|
||||
mdp3::MDIncrementalRefreshTradeSummary48,
|
||||
mdp3::MDIncrementalRefreshVolume37,
|
||||
mdp3::MDInstrumentDefinitionFuture27,
|
||||
mdp3::MDInstrumentDefinitionFuture54,
|
||||
mdp3::MDInstrumentDefinitionOption41,
|
||||
mdp3::MDInstrumentDefinitionOption55,
|
||||
mdp3::MDInstrumentDefinitionSpread29,
|
||||
mdp3::MDInstrumentDefinitionSpread56,
|
||||
mdp3::QuoteRequest39,
|
||||
mdp3::MDIncrementalRefreshVolume37, mdp3::MDInstrumentDefinitionFuture27,
|
||||
mdp3::MDInstrumentDefinitionFuture54, mdp3::MDInstrumentDefinitionOption41,
|
||||
mdp3::MDInstrumentDefinitionOption55, mdp3::MDInstrumentDefinitionSpread29,
|
||||
mdp3::MDInstrumentDefinitionSpread56, mdp3::QuoteRequest39,
|
||||
mdp3::SecurityStatus30, mdp3::SnapshotFullRefresh38,
|
||||
mdp3::SnapshotFullRefresh52, mdp3::SnapshotFullRefreshOrderBook44,
|
||||
mdp3::SnapshotFullRefreshOrderBook53>;
|
||||
|
||||
Reference in new issue
Block a user