6#include <nlohmann/json.hpp>
14#include <unordered_map>
22[[nodiscard]]
inline bool is_enabled_feed(
const nlohmann::json &feed, std::string_view type) {
23 return feed.value(
"enabled",
true) && feed.value(
"type", std::string()) == type;
27[[nodiscard]]
inline bool has_enabled_feed(
const nlohmann::json &instance, std::string_view type) {
28 for (
const auto &feed : instance.value(
"md_feeds", nlohmann::json::array())) {
39 std::string_view feed_type,
const std::string &owner, std::string_view venue) {
40 for (
const auto &feed : instance.value(
"md_feeds", nlohmann::json::array())) {
41 if (
is_enabled_feed(feed, feed_type) && feed.contains(
"control_channel")) {
42 const uint16_t port = feed[
"control_channel"].value(
"port", uint16_t{0});
44 claim(ports, port, owner,
"pcap control channel port", venue);
52template <
typename Queue>
53[[nodiscard]] std::shared_ptr<md_feed::ReplayGate>
make_replay_gate(
const nlohmann::json &instance,
54 std::string_view feed_type, Queue &md_queue) {
58 return std::make_shared<md_feed::ReplayGate>([&md_queue] {
return md_queue.initial_reading_index(); });
63 std::string_view kind,
const std::string &name) {
64 if (has_pcap_feed && live_feeds != 0) {
65 throw std::runtime_error(std::format(
"{}: {} '{}' mixes a pcap feed with live feeds", venue, kind, name));
71template <
typename Event,
typename Feed>
74 event.transact_time = feed->event_time_ns();
Helpers for a venue whose one config entry describes several independent exchange instances,...
Event replay_stamped(Event event, const Feed *feed)
event with its time set from the replay: a replay is stamped on the wall clock, not with the capture'...
bool has_enabled_feed(const nlohmann::json &instance, std::string_view type)
True when the instance's md_feeds has an enabled feed of type.
void claim(std::unordered_map< T, std::string > &claimed, const T &value, const std::string &owner, std::string_view what, std::string_view venue)
Records that instance owner uses value.
std::shared_ptr< md_feed::ReplayGate > make_replay_gate(const nlohmann::json &instance, std::string_view feed_type, Queue &md_queue)
The gate a replaying instance's publisher waits on, or null when its config has no enabled feed of fe...
void claim_pcap_control_ports(std::unordered_map< uint16_t, std::string > &ports, const nlohmann::json &instance, std::string_view feed_type, const std::string &owner, std::string_view venue)
Claims the TCP control port of each enabled pcap feed of instance for owner.
bool is_enabled_feed(const nlohmann::json &feed, std::string_view type)
True for a md_feeds entry of type that is not disabled.
void reject_pcap_with_live_feeds(bool has_pcap_feed, size_t live_feeds, std::string_view venue, std::string_view kind, const std::string &name)
Throws when a replay and live feeds would both write the one book.